struts-config.xml里面加这个
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml,
/WEB-INF/action-servlet.xml,,,,,,,"/>
这是《Spring Live》Sample Chapter.pdf里的例子
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/applicationContext.xml,
/WEB-INF/action-servlet.xml,,,,,,,"/>
这是《Spring Live》Sample Chapter.pdf里的例子
解决方案 »
- csdn会员快到期,还有1100多次免积分下载,可帮助需要的人下载
- 第一次写xml的DTD,请大家指教!进者有分
- EJB JPA 事物管理,用JBOSS发布
- jsp报这样的错,各位进来看下
- 在运行the j2ee tutorial里面CartApp例子的时候,出现如下错误
- 北京求职java程序员
- commons-fileupload中如何取得其它字段的值?急。
- 求教关于SQL Server 2000 JDBC驱动
- sun.jdbc.odbc.JdbcOdbcDriver类为什么找不到?
- 请教:怎样用java来写Windows服务?
- 请问为什么我做的CMP Create后在数据库中并不能产生数据
- 这个问题都解决不了,民女不想活了~~~~~~~~~~~~~啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊!!!!!
extends Object
Performs the actual initialization work for the root application context. Called by ContextLoaderListener and ContextLoaderServlet. Looks for a "contextClass" parameter at the web.xml context-param level to specify the context class type, falling back to the default of XmlWebApplicationContext if not found. With the default ContextLoader implementation, any context class specified needs to implement ConfigurableWebApplicationContext. Passes a "contextConfigLocation" context-param to the context instance, parsing it into potentially multiple file paths which can be separated by any number of commas and spaces, like "applicationContext1.xml, applicationContext2.xml". If not explicitly specified, the context implementation is supposed to use a default location (with XmlWebApplicationContext: "/WEB-INF/applicationContext.xml"). Note: In case of multiple config locations, later bean definitions will override ones defined in earlier loaded files, at least when using one of Spring's default ApplicationContext implementations. This can be leveraged to deliberately override certain bean definitions via an extra XML file. Above and beyond loading the root application context, this class can optionally load or obtain and hook up a shared parent context to the root application context. See the loadParentContext(ServletContext) method for more information. 1.使用监听器或servlet
这两种方式都可以处理多个配置文件的问题,区别见上。
要使用多个配置文件只需在web.xml中加入一个
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext-hibernate.xml,/WEB-INF/applicationContext.xml</param-value>
</context-param>
多个配置文件用逗号或空格分开即可,具体原因请见上面ContextLoader的描述2.使用ClassPathApplicationContext。这个类会自动从classpath目录中加载所有的配置文件,不过这个类好像只适用本地调试时用的。3.通过一个父配置文件将所有子配置文件导入。
在配置文件中有一个标签import,它能把其它的bean定义配置文件导入到父文件夹中4.通过FileSystemXmlApplicationContext
FileSystemXmlApplicationContext的构造函数是一个字符串数组这个数组就是保存配置文件的路径
发现其配置多个配置文件如下!可以说得上是另一种方法吧.只是遵循一种命名规则!<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>比如说用到Hibernate,则把hibernate相关的配置放在applicationContext-hibernate.xml这一个文件,而一些全局相关的信息则放在applicationContext.xml,其他的配置类似.这样就可以加载了,不必写用空格或是逗号分开!