【问题标题】:Spring : Exception starting filter springSecurityFilterChainSpring:异常启动过滤器springSecurityFilterChain
【发布时间】:2013-04-05 05:21:24
【问题描述】:

我正在尝试使用Spring 3.1.2-Release 编写应用程序。应用服务器是Tomcat 7。 当我启动服务器时,出现此错误:

严重:异常启动过滤器 springSecurityFilterChain org.springframework.beans.factory.NoSuchBeanDefinitionException: 否

名为“springSecurityFilterChain”的 bean 定义在 org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:553) 在 org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095) 在 org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277) 在 org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) 在 org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1102)

这是我的配置文件:

web.xml
<display-name>myTest</display-name>

<context-param>     
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>

<context-param>
    <param-name>defaultHtmlEscape</param-name>
    <param-value>true</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>
<listener>
    <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
</listener>

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

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

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

这是root-context.xml

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:c="http://www.springframework.org/schema/c" xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">


<context:annotation-config />

<context:component-scan base-package="com.myTest.db.entities"/>
<context:component-scan base-package="com.myTest.services"/>
<context:component-scan base-package="com.myTest.web"/>

<import resource="mvc-config.xml" />

这是

security-config.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.1.xsd
                    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">

<!-- Additional filter chain for normal users, matching all other requests -->
<http pattern="/resources/**" security="none" />

<http use-expressions="true">
    <intercept-url pattern="/login" access='isAnonymous()' requires-channel='http' />       
    <intercept-url pattern="/" access='permitAll' requires-channel='http'/>
    <intercept-url pattern='/**' access='isAuthenticated()' requires-channel='http'/>
    <form-login login-page="/login" authentication-failure-url="/login" default-target-url="/welcome" />
    <access-denied-handler ref="accessDeniedHandler" />   
    <logout logout-url="/logout" logout-success-url="/" />
</http>

<beans:bean id="accessDeniedHandler" class="org.springframework.security.web.access.AccessDeniedHandlerImpl">
    <beans:property name="errorPage" value="/WEB-INF/pages/error.jsp"/>
</beans:bean>

 <authentication-manager>
    <authentication-provider user-service-ref="userAuthenticationService">
        <password-encoder hash="sha-256">
            <salt-source user-property="salt" />
        </password-encoder>
    </authentication-provider>
</authentication-manager>

<!-- User Detail Services -->
<beans:bean id="userAuthenticationService" class="com.myTest.security.AuthenticationServiceImpl" />

有什么想法吗?

【问题讨论】:

    标签: java spring spring-security configuration-files web.xml


    【解决方案1】:

    您在 web.xml 中缺少 security-config.xml 条目

    你可能需要这样的东西:

    <param-value>/WEB-INF/spring/security-config.xml</param-value>
    

    行后

    <param-value>/WEB-INF/spring/root-context.xml</param-value>
    

    在 web.xml 中

    【讨论】:

    • 感谢您的回复。我真的忘了在我的root-config.xml 中导入security-config.xml,而我有其他导入&lt;import resource="mvc-config.xml" /&gt;
    • 我只使用 java 配置。关注此博客codehustler.org/blog/… 我遇到了上述错误,我尝试了所有配置但没有任何帮助,也在 onStartup() DelegatingFilterProxy springSecurityFilterChain = new DelegatingFilterProxy("springSecurityFilterChain");动态注册 = servletContext.addFilter("springSecurityFilterChain", springSecurityFilterChain); registration.addMappingForUrlPatterns(null,false, "/*"); 请告诉我可能是什么问题
    • @89n3ur0n 最好将其作为一个单独的问题提出。
    猜你喜欢
    • 2013-09-28
    • 2012-02-10
    • 2015-09-03
    • 2016-11-19
    • 1970-01-01
    • 2014-05-28
    • 2013-04-29
    • 2016-02-17
    • 2014-10-27
    相关资源
    最近更新 更多