Where do you define spring bean configuration files

I split the spring bean configuration files as follows:

MyApp-service.xml MyApp-servlet.xml

However, I get the error message:

Error creating bean with the name "beanName" defined in the ServletContext resource [/WEB-INF/myapp-servlet.xml]: the link to the bean 'beanService' cannot be resolved when setting the bean 'beanService' property; The nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: There is no bean named 'beanService' 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 the beanService is defined.

What file / location is running in?

thanks

+4
source share
2 answers

It is 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 can put:

 <import resource="myapp-service.xml"/> 
+6
source

if you want to include more application files and create 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> 

wildcards also work, applicationContext * will have the same effect.

if you load the spring context manually, for example, from the code:

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

All Articles