开发者

Where do you define spring bean configuration files

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


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜