views:

91

answers:

2

I am separating my spring bean configuration files as follows:

myapp-service.xml myapp-servlet.xml

However I am getting the error;

Error creating bean with name 'beanName' defined in ServletContext resource [/WEB-INF/myapp-servlet.xml]: Cannot resolve reference to bean 'beanService' while setting bean property 'beanService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'beanService' is defined

All I need to do (I think) is figure out how to tell Spring to read the myapp-service.xml file where the path to beanService is defined.

Which file/location is that done in?

Thanks

+3  A: 

It's defined in your web.xml:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

Alternatively in myapp-servlet.xml you could put:

<import resource="myapp-service.xml"/>
cletus
+1  A: 

if you like to include more applicationContext files and are indeed developing a web application:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/applicationContext-1.xml,
/WEB-INF/applicationContext-2.xml
</param-value>
</context-param>

also wildcarding works, applicationContext* will have the same effect here.

if you are bootstrapping spring context by hand e.g from code:

ApplicationContext context = 
new ClassPathXmlApplicationContext(new String[] { "applicationContext-1.xml", "applicationContext-2.xml" });
abalogh