2016-08-18 2 views
2

Springを使用してWebサービスで認証を追加しようとしています。 サンプルコードとしてthis resourceを参照しました。 残念ながら、例外が発生しています。springSecurityFilterChainという名前のBeanは、Spring Restful Webサービス認証の例外として定義されていません。

org.springframework.beans.factory.NoSuchBeanDefinitionException:という名前のBeanは 'springSecurityFilterChain' 私はGoogleで多くの参照を介して行っている

を定義しています。しかし、私は解決策を見いださなかった。だから誰も私がここで間違って何を解決することをお勧めしますか?

次の設定を使用しています。

スプリングバージョン - 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

ではなく、あなたのapplication.xmlファイルまたはあなたの派遣-servlet.xmlファイルで、あなたの春-のsecurity.xmlファイルをインポートしてみてください。

私は問題がコンテキストファイルの読み込みの順番にあると思います。 J2EEコンテナでは、ロードする順序はリスナー、フィルタ、サーバーです。アプリケーションコンテキストファイルがリスナーによって読み込まれると、Springのセキュリティフィルタの前にロードされます。しかし、ディスパッチャサーブレットがフィルタの後にロードされたとして、あなたはそれがだ派遣-servlet.xmlファイルで、あなたの春のセキュリティファイルをインポートする場合、それは...フィルタのインスタンス化時に

よろしく、

ロイック

利用できません
0

インポートが機能しない可能性があります。このようのsecurity.xmlをインポートしよう:

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

私のspring-security.xmlはdispatcher-servletと同じ場所に配置されているので、クラスパスを明示的に指定する必要はありません。 –

関連する問題