5

我正在尝试基本的弹簧安全设置。我正在使用 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: Error created bean with name 'org.springframework.security.filterChains': Initialization of bean failed; 嵌套异常是 java.lang.NoSuchFieldError: NULL。

谁能帮我?

4

2 回答 2

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。在明确添加这些依赖项后,问题就消失了。

于 2012-06-14T18:59:29.677 回答
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也是一样的

于 2012-04-19T06:14:12.263 回答