简体   繁体   English

没有定义名为“ springSecurityFilterChain”的bean

[英]No bean named 'springSecurityFilterChain' is defined

I am having some issues setting up spring security It seems it cant find the springSecurityFilterChain bean My spring security config: 我在设置Spring Security时遇到一些问题似乎找不到springSecurityFilterChain bean我的spring安全配置:

<beans:beans xmlns:beans="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:p="http://www.springframework.org/schema/p"
    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/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">

<http auto-config="true">
    <intercept-url pattern="/**" access="ROLE_USER"/>
</http>

<authentication-manager>
    <authentication-provider>
        <user-service>
            <user name="user1" password="1234" authorities="ROLE_USER" />
        </user-service>
    </authentication-provider>

</authentication-manager>

</beans:beans>

My web.xml 我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

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

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

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

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

</web-app>

My xml file locations: 我的xml文件位置:

在此处输入图片说明

I think it can't find the /WEB-INF/config/security-config.xml 我认为找不到/WEB-INF/config/security-config.xml

I think that the reason of your problem can be in that your xml configuration file for spring security isn't loaded when you start your web app. 我认为问题的原因可能是因为在启动Web应用程序时未加载用于弹簧安全性的xml配置文件。

To fix this you should specify all your XML config files in web.xml like that: 要解决此问题,您应该像这样在web.xml指定所有XML配置文件:

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

If you have your config files in classpath (not WEB-INF folder or it's subfolders) then you can specify list of config files in such way; 如果您的配置文件位于classpath (而不是WEB-INF文件夹或其子文件夹),则可以通过这种方式指定配置文件列表;

<param-value>
    classpath:applicationContext.xml,
    classpath:spitter-security.xml
</param-value>

And also you need to add special listener that will load your config files: 另外,您还需要添加特殊的监听器,以加载配置文件:

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JavaConfig 没有定义名为“springSecurityFilterChain”的 bean - JavaConfig No bean named 'springSecurityFilterChain' is defined 如何修复未定义名为“ springSecurityFilterChain”的bean - How to fix No bean named 'springSecurityFilterChain' is defined 没有定义名为“ springSecurityFilterChain”的bean Java配置 - No bean named 'springSecurityFilterChain' is defined Java Config spring mvc没有定义名为&#39;springSecurityFilterChain&#39;的bean - spring mvc No bean named 'springSecurityFilterChain' is defined 没有名为'springSecurityFilterChain'的bean使用javaconfig定义错误 - No bean named 'springSecurityFilterChain' is defined error with javaconfig Spring Security-未定义名为“ springSecurityFilterChain”的Bean - Spring Security - No bean named 'springSecurityFilterChain' is defined 未定义名为“ springSecurityFilterChain”的bean-Spring 4 Java配置 - No bean named 'springSecurityFilterChain' is defined - Spring 4 Java configuration 没有名为“ springSecurityFilterChain”的bean - No bean named 'springSecurityFilterChain' available “未定义名为&#39;springSecurityFilterChain&#39;的bean” Java Config Spring安全性 - “No bean named 'springSecurityFilterChain' is defined” Java Config Spring security Web.xml和Java Config的组合未定义名为“ springSecurityFilterChain”的bean - No bean named 'springSecurityFilterChain' is defined in combination of Web.xml and Java Config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM