Spring 安全性 - 创建 bean 'org.springframework.security.filterChains 时出错



我正在尝试基本的弹簧安全性设置。我正在使用 3.1.0.发布我在春季安全 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。

谁能帮我?

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

您的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也是如此

最新更新