org.springframework.beans.factory.NoSuchBeanDefinitionException:没有名为';springSecurityFilterChain';定义了基于Java的配置

org.springframework.beans.factory.NoSuchBeanDefinitionException:没有名为';springSecurityFilterChain';定义了基于Java的配置,java,spring,spring-mvc,spring-security,Java,Spring,Spring Mvc,Spring Security,尝试解析org.springframework.beans.factory.NoSuchBeanDefinitionException:在基于Java的配置中未定义名为“springSecurityFilterChain”的bean web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmln

尝试解析
org.springframework.beans.factory.NoSuchBeanDefinitionException:在基于Java的配置中未定义名为“springSecurityFilterChain”的bean

web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         id="WebApp_ID" version="3.0">

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

    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>com.examples.config.WebAppConfig</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>

    <error-page>
        <error-code>404</error-code>
        <location>/WEB-INF/views/error/404.jsp</location>
    </error-page>


</web-app>
安全性的SecurityConfig.java文件:

@Configuration
@ImportResource({ "classpath:spring-security-config.xml" })
public class SecurityConfig {

    public SecurityConfig() {
        super();
    }

}
最后是WebAppConfig.java类:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:beans="http://www.springframework.org/schema/beans"
             xmlns="http://www.springframework.org/schema/security"
             xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security.xsd">

    <http auto-config="true">
        <intercept-url pattern="/anonymous*" access="isAnonymous()"/>
        <intercept-url pattern="/login*" access="permitAll"/>
        <intercept-url pattern="/**" access="isAuthenticated()"/>

        <form-login login-page='/login.html' login-processing-url="/perform_login"
                    default-target-url="/homepage.html" authentication-failure-url="/login.html?error=true"
                    always-use-default-target="true"/>

        <logout logout-url="/perform_logout" delete-cookies="JSESSIONID"
                success-handler-ref="customLogoutSuccessHandler"/>

    </http>

    <beans:bean name="customLogoutSuccessHandler"
                class="com.examples.config.CustomLogoutSuccessHandler"/>

    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="user1" password="pass1" authorities="ROLE_USER"/>
                <user name="user2" password="pass2" authorities="ROLE_USER"/>
            </user-service>
        </authentication-provider>
    </authentication-manager>
</beans:beans>

现在,我得到了
org.springframework.beans.factory.NoSuchBeanDefinitionException:在我正在进行的Java base Spring安全项目中,没有定义名为“springSecurityFilterChain”的bean。这些东西在注释配置上工作得很好,并且可以很好地进行测试。出于某种原因,Spring在尝试完成Spring安全表单登录示例时抛出了这样一个错误

另外,在spring-security-config.xml中,尝试将
更改为
,但仍然无法解决名为
'springSecurityFilterChain'
的Bean发现异常

在这件事上的任何帮助都将不胜感激。
谢谢,

Spring容器正在尝试在应用程序上下文而不是web应用程序上下文中查找springSecurityFilterChain bean。将spring安全配置更改为包含在根上下文中。

spring容器正在尝试在应用程序上下文而不是web应用程序上下文中查找springSecurityFilterChain bean。将spring安全配置更改为包含在根上下文中。

请提供spring安全的最低配置

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd “>



请提供spring security的最低配置

http://www.springframework.org/schema/beans/spring-beans-3.0.xsd “>



请提供您认为如何解决此问题的更多详细信息。具体来说,过滤器的定义应该放在什么文件中?谢谢。我一直无法解决这个问题。仍在努力解决。请提供更多详细信息,说明您认为如何解决此问题。具体来说,过滤器的定义应该放在什么文件中?谢谢。我一直无法解决这个问题。仍在挣扎。
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns:beans="http://www.springframework.org/schema/beans"
             xmlns="http://www.springframework.org/schema/security"
             xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security.xsd">

    <http auto-config="true">
        <intercept-url pattern="/anonymous*" access="isAnonymous()"/>
        <intercept-url pattern="/login*" access="permitAll"/>
        <intercept-url pattern="/**" access="isAuthenticated()"/>

        <form-login login-page='/login.html' login-processing-url="/perform_login"
                    default-target-url="/homepage.html" authentication-failure-url="/login.html?error=true"
                    always-use-default-target="true"/>

        <logout logout-url="/perform_logout" delete-cookies="JSESSIONID"
                success-handler-ref="customLogoutSuccessHandler"/>

    </http>

    <beans:bean name="customLogoutSuccessHandler"
                class="com.examples.config.CustomLogoutSuccessHandler"/>

    <authentication-manager>
        <authentication-provider>
            <user-service>
                <user name="user1" password="pass1" authorities="ROLE_USER"/>
                <user name="user2" password="pass2" authorities="ROLE_USER"/>
            </user-service>
        </authentication-provider>
    </authentication-manager>
</beans:beans>
<http auto-config='true'>
    <intercept-url pattern="/**" access="ROLE_USER" />
</http>