2015-10-04 81 views
1

我跟隨this tutorial來保護我的GWT應用程序與Spring安全。GWT和Spring安全:org.springframework.beans.factory.NoSuchBeanDefinitionException

然而,把

<!-- 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>/app</url-pattern> 
</filter-mapping> 

<!-- END FILTERS --> 

<!-- BEGIN Listeners --> 

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

<!-- END Listeners --> 

<context-param> 
    <param-name> 
     contextConfigLocation 
    </param-name> 
    <param-value> 
     classpath:/**/spring-config.xml 
    </param-value> 
</context-param> 

到我的web.xml文件導致一個org.springframework.beans.factory.NoSuchBeanDefinitionException例外。堆棧跟蹤:

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:660) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1157) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:280) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198) 
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:962) 
    at org.springframework.web.filter.DelegatingFilterProxy.initDelegate(DelegatingFilterProxy.java:324) 
    at org.springframework.web.filter.DelegatingFilterProxy.initFilterBean(DelegatingFilterProxy.java:235) 
    at org.springframework.web.filter.GenericFilterBean.init(GenericFilterBean.java:199) 
    at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:281) 
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:262) 
    ... 

我不明白爲什麼我得到這個異常 - 我錯過了什麼?

回答

0

DelegatingFilterProxy是一個Spring Framework類,它委派了一個過濾器實現,該實現在應用程序上下文中被定義爲一個Spring bean。在這種情況下,該bean被命名爲「springSecurityFilterChain」,它是由命名空間創建的用於處理Web安全性的內部基礎架構Bean。請注意,您不應該自己使用這個bean名稱。一旦你將這個添加到你的web.xml中,你就可以開始編輯你的應用程序上下文文件了。 Web安全服務使用元素進行配置。

您應該檢查你的Spring配置,依賴...

而且,這裏是 http://www.mkyong.com/spring-security/spring-security-hello-world-example/

0

有你在web.xml中定義的context-param簡單的Spring安全的好榜樣?對於例如,

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     classpath*:/META-INF/spring/applicationContext-security.xml 
     classpath*:/META-INF/spring/applicationContext.xml 
     classpath*:/META-INF/spring/applicationContext-gwt-dispatch.xml 
    </param-value> 
    </context-param> 

而在你的Spring應用程序上下文,你必須聲明一個Spring bean的XML文件 「的applicationContext-security.xml文件」,在下面這種情況下,

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:security="http://www.springframework.org/schema/security" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd 
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

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

    <security:user-service id="userService"> 
    <security:user name="user" password="user" authorities="ROLE_USER" /> 
    <security:user name="admin" password="admin" authorities="ROLE_USER, ROLE_ADMIN" /> 
    </security:user-service> 

    ... 
    <alias name="filterChainProxy" alias="springSecurityFilterChain" /> 

    <bean id="filterChainProxy" class="org.springframework.security.web.FilterChainProxy"> 
    <security:filter-chain-map path-type="ant"> 
     <security:filter-chain 
     filters="securityContextFilter, logoutFilter, formLoginFilter, requestCacheFilter, 
      servletApiFilter, rememberMeFilter, anonFilter, sessionMgmtFilter, exceptionTranslator, filterSecurityInterceptor" 
     pattern="/**" /> 
    </security:filter-chain-map> 
    </bean> 
    <bean 
    ... 
    </bean> 
    ... 
</beans> 

編號:https://github.com/dmartinpro/gwt-security/tree/master/gwt-security-sample

+0

嗨!嗯..但你在哪裏實際聲明'springSecurityFilterChain'? – displayname

+0

這是filterChainProxy的別名,答案已更新。 – kolunar

+0

嗨!對不起,遲到的答案,但我很忙,不能繼續這一點,直到現在。那麼,我真的沒有得到這個。您發佈的鏈接在哪裏聲明瞭它的FilterChainProxy,以及我發佈的示例在哪裏做了?而我不能只是改變'filterChainProxy'到'springSecurityFilterChain'? – displayname