0

Quick question. Can you reference Spring classes in the applicationContext.xml, when they are in another jar which you webApp uses?

The JAR (a common jar that contains all my servries and daos etc) is in the WAR file, but when I try to reference a service through the applicationContext.xml, I get the following error:-

Error creating bean with name 'com.myproject.common.test.impl.TestServiceImpl' defined in ServletContext resource [/WEB-INF/context/spring-context.xml]: Instantiation of bean failed; nested exception is java.lang.IllegalStateException: No bean class specified on bean definition 

(Note spring-context.xml is imported into the applicationContext.xml without error.)

My context XML:

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean id="com.myproject.common.test.impl.TestServiceImpl"> <property name="genericDao" ref="genericDao" /> </bean> </beans> 

My App packages are all under com.myproject.web My common JARS all under com.myproect.common

2
  • Once you do what @combinatorics mentioned. Ensure, the jar file is in your classpath. Commented Nov 14, 2012 at 1:46
  • Cheers for that MasterV, it is and it worked. Commented Nov 14, 2012 at 23:27

1 Answer 1

5

Your bean element needs a class attribute:

<bean id="myTestServiceImpl" class="com.myproject.common.test.impl.TestServiceImpl"> <property name="genericDao" ref="genericDao" /> </bean> 

The id attribute is just an identifier for the referencing the bean elsewhere in the bean files. The class attribute supplies the name of the class the bean represents.

Sign up to request clarification or add additional context in comments.

1 Comment

Oh my god I'm so stupid! Guilty of cop-n-pasting from my dao-context.xml and overwriting id="..." class="..." and turning it into id="..."

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.