こんにちは皆さん、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 という新しいファイルに貼り付けると、すべて正常に動作します。コンテキスト ファイル名が servlet-context.xml であることを web.xml に伝えたので、これは私にとって混乱を招きます。コンテキスト ファイルを appServlet-servlet.xml と呼ぶ必要がありますか?? もちろん、servlet-context.xml を削除して appServlet-servlet.xml を残して web.xml に指定すると、問題なく動作します。
アプリでスプリング セキュリティを使用する場合、コンテキスト ファイルを appServlet-servlet.xml として呼び出す必要があるかどうかを知りたいだけです。