복붙노트

[SPRING] 이미 만들어진 개체에 DaoAuthenticationConfigurer를 적용 할 수 없습니다.

SPRING

이미 만들어진 개체에 DaoAuthenticationConfigurer를 적용 할 수 없습니다.

이 예외가 발생합니다.

[WARN] org.springframework.web.context.support.GenericWebApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountResource': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private io.ilopezluna.japanathome.service.UserService io.ilopezluna.japanathome.web.rest.AccountResource.userService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.security.crypto.password.PasswordEncoder io.ilopezluna.japanathome.service.UserService.passwordEncoder; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'securityConfiguration': Injection of autowired dependencies failed; nested exception is java.lang.IllegalStateException: Cannot apply org.springframework.security.config.annotation.authentication.configurers.userdetails.DaoAuthenticationConfigurer@54aa5730 to already built object
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:293) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1186) ~[spring-beans-4.0.7.RELEASE.jar:4.0.7.RELEASE]

https://travis-ci.org/ilopezluna/japan-at-home/builds/37866955에서 자세한 내용을 볼 수 있습니다.

이 예외는 테스트를 실행하는 동안 발생합니다. 하지만 내 localhost에 그것을 재현 할 수 없다, 나는 항상 빌드 성공을 얻을 : S

해결법

  1. ==============================

    1.2 일이 걸렸지 만 마침내 이것을 해결했다고 생각합니다. 내 SecurityConfiguration 클래스에는 다음과 같은 메서드가 있습니다.

    2 일이 걸렸지 만 마침내 이것을 해결했다고 생각합니다. 내 SecurityConfiguration 클래스에는 다음과 같은 메서드가 있습니다.

    @Configuration
    @EnableWebMvcSecurity
    @EnableGlobalMethodSecurity(jsr250Enabled=true, prePostEnabled=true)
    public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    
        @Autowired
        public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(authenticationService);
        }
    
    }
    

    configureGlobal 메소드를 configure 메소드로 대체했습니다.

        @Override
        public void configure(AuthenticationManagerBuilder auth) throws Exception {
            auth.userDetailsService(authenticationService);
        }
    

    그리고 이제 모든 것이 잘 작동합니다.

    이 답변에 따르면 configureGlobal을 사용하면 전역 메소드 보안 또는 다른 HttpSecurity (WebSecurityConfigurerAdapter)에 의해 AuthenticationManager가 허용됩니다.

    위에서 볼 수 있듯이 Web MVC 보안과 전역 메서드 보안을 모두 사용할 수 있습니다. 내 단위 테스트에 따르면이 두 가지 방법이 계속 변경되지만이 변경 사항이 올바른지 (즉, 전역 방식 보안을 올바르게 구성하고 있는지) 또는이 문제에 또 다른 문제가 있는지에 대한 내 사무실의 토론이 있습니다. 해결책.

    우리는 문제의 근본 원인이 Spring 버그의 일부 유형, 아마도 경합 상태라고 생각합니다. 그럴 것 같지는 않지만 문제는 프로젝트에 빈 클래스를 추가 할 때만 나타났습니다. 클래스의 패키지 또는 이름이 무엇인지는 중요하지 않았습니다.

  2. from https://stackoverflow.com/questions/26348877/can-not-apply-daoauthenticationconfigurer-to-already-built-object by cc-by-sa and MIT license