【问题标题】:Fixing No bean named 'springSecurityFilterChain' is defined修复没有定义名为“springSecurityFilterChain”的bean
【发布时间】:2014-03-31 05:25:57
【问题描述】:

我遇到了这个问题。 Spring 安全 3.1.3.RELEASEE。这是一个简单的基于 Spring 表单的登录安全性。我收到一个异常,只要服务器启动,就没有定义名为“springSecurityFilterChain”的 bean。

WEB.XML -

    <!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml</param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/spring/appServlet/servlet-context.xml, 
                /WEB-INF/spring/appServlet/login-security.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- 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>

登录--SECURITY.XML -

<security:http auto-config="true">
        <security:intercept-url pattern="/welcome*" access="ROLE_USER" />
        <security:form-login login-page="/login" default-target-url="/welcome"
            authentication-failure-url="/loginfailed" />
        <security:logout logout-success-url="/logout" />
    </security:http>

    <security:authentication-manager>
        <security:authentication-provider>
            <security:user-service>
                <security:user name="mkyong" password="123456" authorities="ROLE_USER" />
            </security:user-service>
        </security:authentication-provider>
    </security:authentication-manager>

I do not get any warnings either. Can somebody please have a look ?

【问题讨论】:

    标签: spring spring-mvc spring-security


    【解决方案1】:

    DelegatingFilterProxy 只能访问所谓的根应用程序上下文。这是ContextLoaderListener 加载的文件。

    所以不要让DispatcherServlet 加载/WEB-INF/spring/appServlet/login-security.xml 将其移动到ContextLoaderListener 的配置中。

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/root-context.xml,/WEB-INF/spring/appServlet/login-security.xml</param-value>
    </context-param>
    

    【讨论】:

    • 感谢 Denium。我刚刚在 root-context.xml 中导入了我的 login-security.xml 并且它工作了
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多