![](/img/trans.png)
[英]Spring Security - No bean named 'springSecurityFilterChain' is defined
[英]Spring 4 Spring Security 3.2.2 No bean named 'springSecurityFilterChain' is defined
我知道这个问题已经问了很多,但似乎没有一个答案对我真正有用。 在过去的两天里,我一直在与Spring Security相撞,并且运气为零。 该文档声称它非常容易安装,但是我不禁感到它缺少某些东西。
我的web.xml:
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>SpringProject</display-name>
<!-- Spring Configuration Files -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:mvcDispatcher-servlet.xml
classpath*:application-security.xml
</param-value>
</context-param>
<!-- Spring Security Filters -->
<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>
<!-- Spring Listeners -->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- MVC Filter -->
<servlet>
<servlet-name>mvcDispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>mvcDispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
而我的application-security.xml:
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<global-method-security secured-annotations="enabled" />
<http use-expressions="true">
<form-login login-page="/login"
login-processing-url="/j_spring_security_check"
default-target-url="/view"
authentication-failure-url="/login?login_error=t" />
<intercept-url pattern="/login" access="isAnonymous()" />
<intercept-url pattern="/**" access="isAuthenticated()" />
</http>
<authentication-manager>
<authentication-provider user-service-ref="userService" />
</authentication-manager>
<user-service id="userService">
<user name="user" password="password" authorities="ROLE_ADMIN" />
</user-service>
</beans:beans>
当我部署(到WAS8.0)并尝试进入登录页面时,出现以下错误:
com.ibm.ws.webcontainer.webapp.WebApp logServletError SRVE0293E: [Servlet Error]-[mvcDispatcher]: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined
如果我从以下位置更改web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath*:mvcDispatcher-servlet.xml
classpath*:application-security.xml
</param-value>
</context-param>
至:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
WEB-INF/mvcDispatcher-servlet.xml
WEB-INF/application-security.xml
</param-value>
</context-param>
我得到错误
[Servlet Error]-[mvcDispatcher]: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace [http://www.springframework.org/schema/security]
我不知道是什么原因造成的,或者为什么Spring Security无法在这里工作。 真令人沮丧。 非常感谢任何帮助,谢谢!
尝试在您的web.xml中执行以下操作。
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/application-security.xml</param-value>
</context-param>
注意:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.