4

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

2 Answers 2

6

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"/>
3

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" });

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.