gpt4 book ai didi

java - Spring 4 Spring Security 3.2.2 未定义名为 'springSecurityFilterChain' 的 bean

转载 作者:行者123 更新时间:2023-12-02 05:43:29 25 4
gpt4 key购买 nike

我知道这个问题已经被问了很多次,但似乎没有一个答案实际上对我有用。在过去的两天里,我一直在与 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 错误]-[mvcDispatcher]:org.springframework.beans.factory.NoSuchBeanDefinitionException:未定义名为“springSecurityFilterChain”的 bean

如果我更改 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 错误]-[mvcDispatcher]:org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置问题:无法找到 XML 模式命名空间的 Spring NamespaceHandler [http://www.springframework.org/架构/安全]

我不知道是什么原因造成的,也不知道为什么 Spring Security 在这里不起作用。这真是令人难以置信的沮丧。非常感谢任何帮助,谢谢!

最佳答案

尝试在您的 web.xml 中执行以下操作。

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/application-security.xml</param-value>
</context-param>

注意:

  • WEB-INF 目录不在类路径上。
  • DispatcherServlet 默认查找 WEB-INF/[servlet-name]-servlet.xml。

关于java - Spring 4 Spring Security 3.2.2 未定义名为 'springSecurityFilterChain' 的 bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24313248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com