Struts2在与Spring整合的时候,applicationContext放在哪儿?

如题,我使用MyEclipse在整合Struts2和Spring的时候,applicationContext.xml文件放在了/WebRoot/WEB-INF/下,可是在web.xml中配置好了后,启动Tomcat总是出现异常,说找不到applicationContext.xml,请问这个文件应该放在哪里?
这样配置对么?
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WebRoot/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<filter>
<filter-name>Struts2Filter</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>Struts2Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
按照rihongedu所说的,可我的还是不行啊,好奇怪,能不能给我发下例子呢?谢谢了
我EMail:cuiyuesw@sina.com

contextConfigLocation配置的是哪里,就是哪里。上面的配置是不对的!

如:
/WEB-INF/applicationContext.xml就是在/WEB-INF文件夹下

classpath: applicationContext.xml就是放在你的源文件夹根目录下,最终是在/WEB-INF/classes文件夹下。

一句话就是,把/WebRoot/WEB-INF/applicationContext.xml 换成 /WEB-INF/applicationContext.xml,(前面不要加上下文根!), 然后把applicationContext.xml放到/WEB-INF目录下即可。
温馨提示:内容为网友见解,仅供参考
第1个回答  2009-03-28
一般struts与spring整合时,都是将spring最为插件整合到struts中
我把spring配置文件放在了classes目录下边,然后在struts配置文件中这样配置
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />
</plug-in>
第2个回答  2019-11-20
一般struts与spring整合时,都是将spring最为插件整合到struts中
我把spring配置文件放在了classes目录下边,然后在struts配置文件中这样配置
第3个回答  2009-03-30
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<display-name>asom</display-name>
<!-- 根据默认的配置文件来初试化spring 容器 -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>

<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>/index.action</welcome-file>
</welcome-file-list>
</web-app>
applicationContext.xml放在WEB-INF文件夹下就对了
第4个回答  2009-03-28
放的位置对着的,是前面的context-param位置标错了吧。
相似回答