Spring Security-Error创建bean'org.springframework.security.filterChains'

时间:2012-04-18 19:29:02

标签: spring security

我正在尝试基本的弹簧安全设置。我正在使用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。

任何人都可以帮助我吗?

2 个答案:

答案 0 :(得分:11)

问题的实际原因似乎是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。明确地添加这些依赖项后,问题就消失了。

答案 1 :(得分:0)

您的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 相同