嗨,大家好,我正在使用Spring 3.2.3,hibernate 4.2.2和org.springframework.security 3.0.5。在春季开始使用安全性之前,我的上下文文件称为servlet-context.xml,并且一切正常。由于我在尝试运行应用程序时开始使用org.springframework.security 3.0.5,因此出现以下错误:
java.io.FileNotFoundException: Could not open ServletContext resource [/WEB-INF/appServlet-servlet.xml]
我的web.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">
<!-- Spring MVC -->
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/servlet-context.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
<!-- Spring Security -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注意,我正在指定我的servlet-context.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/servlet-context.xml,
/WEB-INF/spring-security.xml
</param-value>
</context-param>
如果我这样保留我的web.xml并将servlet-context.xml内容复制/粘贴到一个名为appServlet-servlet.xml的新文件中,则一切正常。因为我告诉web.xml我的上下文文件名是servlet-context.xml,所以这使我感到困惑。我是否被迫将上下文文件称为appServlet-servlet.xml ??。当然,如果我删除servlet-context.xml并保留appServlet-servlet.xml来进行web.xml的规范,则可以正常工作。
我只是想知道如果要在我的应用程序中使用spring安全性,是否必须将我的上下文文件称为appServlet-servlet.xml。
这并不奇怪。春天是这样工作的。由于您的DispatchServlet名称为appServlet,因此Spring会自动尝试查找具有相同名称的servlet上下文,此处为“ appServlet-servlet.xml”。
这是一个可能有所帮助的页面:http : //syntx.io/difference-between-loading-context-via-dispatcherservlet-and-contextloaderlistener/
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句