2016-08-18 8 views
2

스프링을 사용하여 웹 서비스에 인증을 추가하려고합니다. 샘플 코드로 this resource을 언급했습니다. 하지만 불행히도 예외가 발생합니다.'springSecurityFilterChain'이라는 Bean은 스프링 편안한 웹 서비스 인증을 위해 정의되지 않았습니다.

org.springframework.beans.factory.NoSuchBeanDefinitionException은 'springSecurityFilterChain'라는 이름의 빈 구글에 많은 참조를 통해

내가 갈을 정의하지 않습니다. 그러나 나는 해결책을 찾지 못했습니다. 그럼 아무도 제가 여기서 잘못하고있는 어떤 해결책을 제안 할 수 있습니까?

다음 구성을 사용 중입니다.

봄 버전 - 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" /> 

봄 보안. xxx

<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 컨테이너에서로드 순서는 listener, filter, server입니다. 리스너가 응용 프로그램 컨텍스트 파일을로드하면 스프링 보안 필터 전에로드됩니다. 디스패처 서블릿이 필터 후로드로 당신이 당신의 봄 보안 파일을 가져 오는 경우 그러나,

루이

을이 필터 인스턴스화 시간에 사용할 수 없습니다 파일 ...

감사-servlet.xml 파일의 파견 것

0

아마도 가져 오기가 작동하지 않을 수 있습니다. 이 같은 security.xml을 가져보십시오 :

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

spring-security.xml이 dispatcher-servlet과 같은 위치에 있으므로 클래스 경로를 명시 적으로 제공 할 필요가 없습니다. –