2013-08-26 99 views
0

您好我正在嘗試按照本教程http://www.baeldung.com/2011/10/31/securing-a-restful-web-service-with-spring-security-3-1-part-3/#config在我的項目中實現spring安全性,我得到運行我的程序 -Spring security- org.springframework.beans.factory.BeanCreationException:創建名爲'org.springframework.security.filterChains'的bean時出錯'

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 at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:532)

我的web.xml,而下面的異常看起來喜歡 -

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
    xsi:schemaLocation=" 
     http://java.sun.com/xml/ns/javaee 
     http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> 

    <display-name>Spring MVC Application</display-name> 

    <!-- Spring root --> 
    <context-param> 
     <param-name>contextClass</param-name> 
     <param-value> 
     org.springframework.web.context.support.AnnotationConfigWebApplicationContext 
     </param-value> 
    </context-param> 
    <context-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>org.baeldung.spring</param-value> 
    </context-param> 

    <listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <!-- Spring child --> 
    <servlet> 
     <servlet-name>api</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>api</servlet-name> 
     <url-pattern>/api/*</url-pattern> 
    </servlet-mapping> 

    <!-- Spring Security --> 
    <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> 

    <!-- <welcome-file-list> --> 
    <!-- <welcome-file>index.html</welcome-file> --> 
    <!-- </welcome-file-list> --> 

</web-app> 

和我webSecurityConfig.xml看起來喜歡 -

http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd「>

<http use-expressions="true" entry-point-ref="restAuthenticationEntryPoint"> 
    <intercept-url pattern="/api/**" access="isAuthenticated()" /> 

    <sec:form-login authentication-success-handler-ref="mySuccessHandler" /> 

    <logout /> 
</http> 

<beans:bean id="mySuccessHandler" class="org.baeldung.security.MySavedRequestAwareAuthenticationSuccessHandler" /> 

<authentication-manager alias="authenticationManager"> 
    <authentication-provider> 
     <user-service> 
      <user name="temporary" password="temporary" authorities="ROLE_ADMIN" /> 
      <user name="user" password="userPass" authorities="ROLE_USER" /> 
     </user-service> 
    </authentication-provider> 
</authentication-manager> 

我知道這是org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.filterChains'可能重複的,但我試圖解決方案無濟於事,這可能是因爲我仍然是泉水的新手。任何幫助,高度讚賞。

我加載websecurityconfig.xml從SecSecurityConfig.java在org.baeldung.spring框架,它看起來喜歡 -

package org.baeldung.spring; 

import org.springframework.context.annotation.ComponentScan; 
import org.springframework.context.annotation.Configuration; 
import org.springframework.context.annotation.ImportResource; 

@Configuration 
@ImportResource({ "classpath:webSecurityConfig.xml" }) 
@ComponentScan("org.baeldung.security") 
public class SecSecurityConfig { 

    public SecSecurityConfig() { 
     super(); 
    } 

} 
+0

您可以顯示/發佈您是否正在加載webSecurityConfig.xml文件?根據目前的信息判斷它沒有被加載。 –

回答

0

在堆棧跟蹤信息看,如果你在你的classpath有衝突的框架罐子看起來。當使用maven使用mvn dependency:tree來確定哪些依賴項被使用時,我懷疑你的classpath中有一個較老的spring-beans.jar。

相關問題