2013-06-04 10 views
0

저는 봄에 새로 왔습니다. 나는 보안 설정 파일이로드되지 않습니다 생각 유사한 질문에서 판단하여예외 시작 필터 springSecurityFilterChain - org.springframework.beans.factory.NoSuchBeanDefinitionException

org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'springSecurityFilterChain' is defined 

: 나는 인증이 MySQL을 사용하도록 스프링 시큐리티를 사용하는 것을 시도하고,이 오류가 발생합니다.

내 설정 파일은 SRC/메인/자원/스프링 security.xml에 내가 awt.project.init.WebAppConfig에 포함 :

: 여기
@Configuration 
@EnableWebMvc 
@EnableTransactionManagement 
@ComponentScan("awt.project") 
@ImportResource("classpath:spring-security.xml") 
public class WebAppConfig { 
.... 
} 

은 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_2_5.xsd" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
version="3.0"> 

<!-- Serves static resource content from .jar files such as spring-faces.jar --> 
<servlet> 
    <servlet-name>Resource Servlet</servlet-name> 
    <servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class> 
    <load-on-startup>0</load-on-startup> 
</servlet> 

<!-- Map all /resources requests to the Resource Servlet for handling --> 
<servlet-mapping> 
    <servlet-name>Resource Servlet</servlet-name> 
    <url-pattern>/resources/*</url-pattern> 
</servlet-mapping> 

<!-- Java-based Spring container definition --> 
<context-param> 
    <param-name>contextClass</param-name> 
    <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value> 
</context-param> 

<!-- Location of Java @Configuration classes that configure the components that makeup this application --> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value> 
    awt.project.init 
    </param-value> 
</context-param> 

<!-- Creates the Spring Container shared by all Servlets and Filters --> 
<listener> 
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
</listener> 

<!-- Processes application requests --> 
<servlet> 
    <servlet-name>appServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value></param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 

<servlet-mapping> 
    <servlet-name>appServlet</servlet-name> 
    <url-pattern>/</url-pattern> 
</servlet-mapping> 


<!-- Secures the application --> 
<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> 
나는에도 classpath:spring-security.xml로 contexConfiguration에서 스프링 security.xml을 포함하지만 여전히 같은 문제를 얻을 시도했다. 여기

봄-security.xml에게 있습니다

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

<http auto-config="true"> 

    <intercept-url pattern="/sec/moderation.html" access="ROLE_MODERATOR" /> 
    <intercept-url pattern="/admin/*" access="ROLE_ADMIN" /> 

    <form-login login-page="/user-login.html" 
     default-target-url="/success-login.html" authentication-failure-url="/error-login.html" /> 
    <logout logout-success-url="/index.html" /> 

</http> 

<authentication-manager> 
    <authentication-provider user-service-ref="customUserDetailsService"> 
     <password-encoder hash="plaintext" /> 
    </authentication-provider> 
</authentication-manager> 

+0

spring-security.xml 파일의 모양은 무엇입니까? –

+0

spring-security.xml을 추가했습니다. –

+0

일부 종속성 불일치가있는 것 같았습니다. 문제가 해결 된 후 문제가 해결되었습니다. –

답변

0

내가 잘못 될 수도 있지만 당신은 AnnotationConfigWebApplicationContext을 사용하고 contextConfigLocation 만 패키지 이름을 지정하면, 봄이 클래스에 대한 해당 패키지 만 검색합니다 스테레오 타입 주석 (@Component, @Controller, @Service 등)이 있으므로 WebAppConfig은 기본적으로 무시됩니다. WebAppConfig의 정규화 된 이름을 contextConfigLocation으로 지정하십시오.

+0

contextelfigLocation에서 awt.project.init.WebAppConfig를 시도했지만 여전히 동일한 오류가 발생했습니다 –

+2

spring-security.xml 파일이로드되고 있음을 확인하는 한 가지 방법은 의도적으로 오류가 발생하는 잘못된 XML을 만드는 것입니다. XML이 유효하지 않음을 나타냅니다. 또는 디버그 로깅을 활성화하여로드 중인지 확인할 수 있습니다. –

+0

네, 시도해 보았습니다.로드 중이 아닙니다 ... 어떻게 올바르게 처리 할 수 ​​있습니까? 그것은 src/main/resources/spring-security.xml에 있습니다. classpath : spring-security.xml이 맞습니까? –

관련 문제