2016-08-18 41 views
2

我想在使用spring的web服務中添加認證。 我已經提到了this resource的示例代碼。 但不幸的是,我得到一個例外。沒有名爲'springSecurityFilterChain'的bean被定義爲春天寧靜的web服務認證異常

org.springframework.beans.factory.NoSuchBeanDefinitionException:沒有名爲 'springSecurityFilterChain' 豆被定義

我已經通過在谷歌的許多參考。但我沒有找到任何解決方案。所以任何人都可以請建議任何解決方案,我在這裏做錯了嗎?

我正在使用以下配置。

Spring版本 - 3.1.1

應用程序上下文 - web.xml中

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
     /WEB-INF/applicationContext.xml 
    </param-value> 
</context-param> 

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

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

<servlet> 
    <servlet-name>dispatcher</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <load-on-startup>2</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>dispatcher</servlet-name> 
    <!--<url-pattern>/*</url-pattern>--> 
    <url-pattern>*.htm</url-pattern> 
</servlet-mapping> 
<session-config> 
    <session-timeout> 
     30 
    </session-timeout> 
</session-config> 
<welcome-file-list> 
    <welcome-file>redirect.jsp</welcome-file> 
</welcome-file-list> 

調度-servlet.xml中

<mvc:annotation-driven/> 

<context:annotation-config/> 

<context:component-scan base-package="com.em.yms.*" /> 

<import resource="spring-security.xml"/> 

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> 
    <property name="mappings"> 
     <props> 
      <prop key="index.htm">indexController</prop> 
     </props> 
    </property> 
</bean> 


<bean id="viewResolver" 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver" 
     p:prefix="/WEB-INF/jsp/" 
     p:suffix=".jsp" /> 

<bean name="indexController" 
     class="org.springframework.web.servlet.mvc.ParameterizableViewController" 
     p:viewName="index" /> 

春天的安全性。 xml

<http auto-config="true"> 
    <intercept-url pattern="/**" access="ROLE_USER" /> 
</http> 

<authentication-manager alias="authenticationManager"> 
    <authentication-provider> 
     <user-service id="authenticationService"> 
      <user name="user" password="123456" authorities="ROLE_USER"/> 
     </user-service> 
    </authentication-provider> 
</authentication-manager> 
+0

你能提供你在這裏使用的依賴嗎? –

+0

你是指我正在使用的彈簧庫嗎? –

+0

是的..彈簧依賴關係 –

回答

1

嘗試導入您的彈簧security.xml文件在您的application.xml文件代替或者派出-servlet.xml文件。

我認爲問題是按照加載上下文文件的順序。在J2EE容器中,加載的順序是監聽器,過濾器和服務器。由於您的應用程序上下文文件由偵聽器加載,因此它將在彈簧安全篩選器之前加載。但作爲調度的servlet過濾器加載後,如果您導入春天的安全文件,在它的派出-servlet.xml文件也不會提供過濾器實例化時...

問候,

盧瓦克

0

也許你的進口不工作。嘗試導入的security.xml這樣的:

<import resource="classpath:/spring-security.xml"/> 
+2

由於我的spring-security.xml放置在與dispatcher-servlet相同的位置,因此我不需要顯式地提供classpath。 –

相關問題