org.springframework.beans.factory.BeanCreationException:创建名为'org.springframework.security.filterChains'的bean时出错

时间:2012-07-12 08:07:32

标签: spring spring-security

我使用STS,Roo和GWT创建了一个新项目,并尝试包含Spring Security。 从那以后我得到以下错误。有谁知道出了什么问题?!

org.springframework.beans.factory.BeanCreationException:创建名为'org.springframework.security.filterChains'的bean时出错:bean的初始化失败;嵌套异常是java.lang.NoSuchFieldError:NULL

堆栈跟踪:

    [INFO] org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains': Initialization of bean failed; nested exception is java.lang.NoSuchFieldError: NULL
[INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
[INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
[INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
[INFO]  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
[INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
[INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
[INFO]  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:567)
[INFO]  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
[INFO]  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
[INFO]  at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:282)
[INFO]  at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:204)
[INFO]  at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
[INFO]  at org.mortbay.jetty.handler.ContextHandler.startContext(ContextHandler.java:543)
[INFO]  at org.mortbay.jetty.servlet.Context.startContext(Context.java:136)
[INFO]  at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
[INFO]  at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
[INFO]  at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
[INFO]  at com.google.gwt.dev.shell.jetty.JettyLauncher$WebAppContextWithReload.doStart(JettyLauncher.java:468)
[INFO]  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
[INFO]  at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
[INFO]  at org.mortbay.jetty.handler.RequestLogHandler.doStart(RequestLogHandler.java:115)
[INFO]  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
[INFO]  at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
[INFO]  at org.mortbay.jetty.Server.doStart(Server.java:222)
[INFO]  at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
[INFO]  at com.google.gwt.dev.shell.jetty.JettyLauncher.start(JettyLauncher.java:672)
[INFO]  at com.google.gwt.dev.DevMode.doStartUpServer(DevMode.java:509)
[INFO]  at com.google.gwt.dev.DevModeBase.startUp(DevModeBase.java:1068)
[INFO]  at com.google.gwt.dev.DevModeBase.run(DevModeBase.java:811)
[INFO]  at com.google.gwt.dev.DevMode.main(DevMode.java:311)
[INFO] Caused by: java.lang.NoSuchFieldError: NULL
[INFO]  at org.springframework.expression.TypedValue.<clinit>(TypedValue.java:32)
[INFO]  at org.springframework.expression.spel.support.StandardEvaluationContext.setRootObject(StandardEvaluationContext.java:88)
[INFO]  at org.springframework.expression.spel.support.StandardEvaluationContext.<init>(StandardEvaluationContext.java:74)
[INFO]  at org.springframework.context.expression.StandardBeanExpressionResolver.evaluate(StandardBeanExpressionResolver.java:124)
[INFO]  at org.springframework.beans.factory.support.AbstractBeanFactory.evaluateBeanDefinitionString(AbstractBeanFactory.java:1299)
[INFO]  at org.springframework.beans.factory.support.BeanDefinitionValueResolver.evaluate(BeanDefinitionValueResolver.java:224)
[INFO]  at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:311)
[INFO]  at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
[INFO]  at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedList(BeanDefinitionValueResolver.java:353)
[INFO]  at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:153)
[INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1360)
[INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
[INFO]  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
[INFO]  ... 29 more

我的web.xml

    <!-- Enable escaping of form submission contents -->
    <context-param>
        <param-name>defaultHtmlEscape</param-name>
        <param-value>true</param-value>
    </context-param>

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

    <filter-mapping>
          <filter-name>springSecurityFilterChain</filter-name>
          <url-pattern>/*</url-pattern>
    </filter-mapping>




    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>



    <filter>
        <filter-name>HttpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>

    <filter>
        <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
        <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>HttpMethodFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Handles Spring requests -->
    <servlet>
        <servlet-name>Weltenbrand</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>



    <servlet>
        <servlet-name>requestFactory</servlet-name>
        <servlet-class>de.roio.weltenbrand.server.CustomRequestFactoryServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Weltenbrand</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>



    <servlet-mapping>
        <servlet-name>requestFactory</servlet-name>
        <url-pattern>/gwtRequest</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>10</session-timeout>
    </session-config>

    <servlet>
     <servlet-name>authServlet</servlet-name>
     <servlet-class>de.roio.weltenbrand.server.authentication.AuthServiceImpl</servlet-class>
    </servlet>

    <servlet-mapping>
     <servlet-name>authServlet</servlet-name>
     <url-pattern>/Weltenbrand/auth</url-pattern>
    </servlet-mapping>

</web-app>

这里是applicationContext.xml:

<bean id="customAuthListener" class="de.roio.weltenbrand.server.authentication.CustomAuthListener"/>

<security:http auto-config="true">
    <security:intercept-url pattern="/gwtspringsecurityproject/**" access="ROLE_USER"/>
    <security:intercept-url pattern="/gwt/**" access="ROLE_USER"/>
    <security:intercept-url pattern="/**/*.html" access="ROLE_USER"/>
    <security:intercept-url pattern="/**" access="IS_AUTHENTICATED_ANONYMOUSLY" />
</security:http>

<bean id="customAuthenticationProvider"
       class="de.roio.weltenbrand.server.authentication.CustomAuthenticationProvider" />   

<security:authentication-manager alias="authenticationManager">
    <security:authentication-provider ref="customAuthenticationProvider"/>
</security:authentication-manager>

<context:property-placeholder location="classpath*:META-INF/spring/*.properties"/>

<context:spring-configured/>

<context:component-scan base-package="de.roio.weltenbrand">
    <context:exclude-filter expression=".*_Roo_.*" type="regex"/>
    <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
</context:component-scan>
<bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="dataSource">
    <property name="driverClassName" value="${database.driverClassName}"/>
    <property name="url" value="${database.url}"/>
    <property name="username" value="${database.username}"/>
    <property name="password" value="${database.password}"/>
    <property name="testOnBorrow" value="true"/>
    <property name="testOnReturn" value="true"/>
    <property name="testWhileIdle" value="true"/>
    <property name="timeBetweenEvictionRunsMillis" value="1800000"/>
    <property name="numTestsPerEvictionRun" value="3"/>
    <property name="minEvictableIdleTimeMillis" value="1800000"/>
    <property name="validationQuery" value="SELECT 1"/>
</bean>
<bean class="org.springframework.orm.jpa.JpaTransactionManager" id="transactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
<tx:annotation-driven mode="aspectj" transaction-manager="transactionManager"/>
<bean class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" id="entityManagerFactory">
    <property name="persistenceUnitName" value="persistenceUnit"/>
    <property name="dataSource" ref="dataSource"/>
</bean>

2 个答案:

答案 0 :(得分:4)

问题的实际原因似乎是spring-security 3.1.X引入了旧版本的spring,这会产生一种无声的冲突。在我的例子中,spring-security-3.1.3.RELEASE在spring-expressions 3.0.7.RELEASE中引入。明确地添加此依赖项之后,问题就消失了。

答案 1 :(得分:0)

有类似的问题,但通过更改弹簧版本得到解决。我改变了所有的春天依赖“

<org.springframework.version>3.2.5.RELEASE</org.springframework.version>
<spring-security.version>3.2.5.RELEASE</spring-security.version>
<spring-aop.version>3.2.5.RELEASE</spring-aop.version>
<org.testng.version>6.8.7</org.testng.version>
<spring-test.version>3.2.5.RELEASE</spring-test.version>`

它有效......