2014-04-24 1 views
1

스프링 보안 인증을 위해 Java-config와 xml-config를 결합하려고합니다. 하지만 오류가 발생했습니다 :이름이 'securityConfig'인 빈을 생성하는 중 오류 발생 : 자동 종속 종속성 삽입 실패

Error creating bean with name 'securityConfig': Injection of autowired dependencies failed

내 코드에 어떤 문제가있는 것 같습니까? 인터넷 검색 결과가 있지만 찾지 못했습니다.

미리 감사드립니다. 네가 나를 도울 수 있기를 바랍니다.

스택 트레이스 :

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfig': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setAuthenticationConfiguration(org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter.setAuthenticationConfiguration(org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} 

자바 설정 : SecurityConfig.java

@Configuration 
@EnableWebMvcSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 

@Override 
protected void configure(HttpSecurity http) throws Exception { 
    http 
    .authorizeRequests() 
     .antMatchers("/webapp/resources/**").permitAll() 
     .anyRequest().authenticated() 
     .and() 
    .formLogin() 
     .loginPage("/login") 
     .permitAll() 
     .and() 
    .logout()          
     .permitAll(); 
} 

@Autowired 
public void registerGlobalAuthentication(
     AuthenticationManagerBuilder auth) throws Exception { 
    auth 
     .inMemoryAuthentication() 
      .withUser("user").password("password").roles("USER"); 
} 
} 

web.xml에 난 이미 내 servlet-에 컴포넌트 스캔을 선언 한

<!-- The definition of the Root Spring Container shared by all Servlets and Filters --> 
<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>/WEB-INF/spring/root-context.xml</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>/WEB-INF/spring/appServlet/servlet-context.xml</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> 

context.xml

<context:component-scan base-package="ph.project.p3.conf" /> 
+0

이 문제를 어떻게 해결 했습니까? –

답변

0

스프링 구성 파일에 <context:component-scan>을 추가해야합니다. 그렇지 않으면 응용 프로그램은 응용 프로그램 컨텍스트에서 빈을 찾아 등록하기 위해 패키지 구조를 검색하지 않습니다.

구문 :<context:component-scan base-package="org.example.<yourapplicationName>"/> 예 : <context:component-scan base-package="oph.project.p3.conf"/>

+0

안녕 @AnilSatija, 응답 주셔서 감사합니다. 위에서 설명한 것처럼 내 servlet-context.xml에서 이미 구성 요소 검사를 선언하고 내 root-context.xml에서도이 검사를 시도했습니다. 나는 또한 "ph.project.p3".conf를 제거하려고했지만 동일한 오류가 발생해도 AuthorizationConfiguration을 autowire 할 수 없습니다. – totoDaryl

1

당신은 @Component 주석을 추가하는 시도 할 수 있습니다. 그렇게하면 자동 와이어 링이 작동합니다.