【问题标题】:Spring Security-Error creating bean 'org.springframework.security.filterChains'Spring Security-Error 创建 bean 'org.springframework.security.filterChains'
【发布时间】:2023-03-02 23:33:01
【问题描述】:

我正在尝试基本的 spring 安全设置。我正在使用 3.1.0.RELEASE 我在spring security xml中有如下:

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

<security:authentication-manager>
<security:authentication-provider>
<security:user-service>
<security:user name="jimi" password="jimispassword" authorities="ROLE_USER,      ROLE_ADMIN" />
<security:user name="bob" password="bobspassword" authorities="ROLE_USER" />
</security:user-service>
</security:authentication-provider>
</security:authentication-manager>

当我访问起始页时,我得到以下异常: org.springframework.beans.factory.BeanCreationExce ption:创建名为“org.springframework.security.filterChains”的bean时出错:bean初始化失败;嵌套异常是 java.lang.NoSuchFieldError: NULL。

谁能帮帮我?

【问题讨论】:

  • org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.security.filterChains”的bean时出错:bean初始化失败;嵌套异常是 java.lang.NoSuchFieldError: NULL at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
  • ******************************web xml*********** contextConfigLocation /WEB-INF/applicationContext-security.xml springSecurityFilterChain org.springframework.web.filter.DelegatingFilterProxyspringSecurityFilterChain/*
  • 欢迎来到 Stackoverflow。一个提示:您可以编辑问题,而不是添加命令,这将使其更具可读性。

标签: spring security


【解决方案1】:

问题的实际原因似乎是 spring-security 3.1.0 引入了旧版本的 spring,从而产生了无声的冲突。在我的例子中,spring-security-3.1.0.RELEASE 引入了 spring-aop、spring-jdbc、spring-tx 和 spring-expression 3.0.6,但我使用的是 spring 3.1.0.RELEASE。明确添加这些依赖项后,问题就消失了。

【讨论】:

  • 这是正确的诊断,为 aop/jdbc/etc 添加 dep 管理,它将修复它:
【解决方案2】:

您的web.xml 好像错过了org.springframework.web.context.ContextLoaderListener

你的web.xml应该有这个元素:

<!-- or in your case /WEB-INF/applicationContext-security.xml -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:META-INF/spring/applicationContext*.xml</param-value>
</context-param>

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<servlet>
    <servlet-name>My-Web-SpringProject</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/webmvc-config.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<filter-mapping>
    <!-- do not change this name! -->
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<!-- it is configured by the parameter contextConfigLocation in the begining -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet-mapping>
    <servlet-name>My-Web-SpringProject</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

说实话,这是Spring 3.0的配置,不过我觉得3.1也是一样的

【讨论】:

    猜你喜欢
    • 2013-08-28
    • 1970-01-01
    • 1970-01-01
    • 2013-06-11
    • 2017-04-17
    • 2013-10-06
    • 2020-07-02
    • 2012-03-28
    • 2015-03-08
    相关资源
    最近更新 更多