【发布时间】:2010-10-10 15:34:52
【问题描述】:
将Spring的配置拆分为多个xml文件的正确方法是什么?
目前有
/WEB-INF/foo-servlet.xml/WEB-INF/foo-service.xml/WEB-INF/foo-persistence.xml
我的web.xml 有以下内容:
<servlet>
<description>Spring MVC Dispatcher Servlet</description>
<servlet-name>intrafest</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/foo-*.xml
</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/foo-*.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
实际问题:
- 这种方法正确/最佳吗?
- 我真的需要在
DispatcherServlet和context-param部分中指定配置位置吗?
我需要记住什么才能从foo-service.xml 引用foo-servlet.xml 中定义的bean?这与在web.xml 中指定contextConfigLocation 有关吗?
更新 1:
我正在使用 Spring 框架 3.0。据我了解,我不需要像这样进行资源导入:
<import resource="foo-services.xml"/>
这是一个正确的假设吗?
【问题讨论】:
标签: spring configuration