CustomAuthenticationProvider는 왜 Autowired를 사용할 수 없나요?
875
작성한 질문수 13
provider를 Service로 등록하고 Autowired로 주입 받았을때 PasswordEncoder에서 문제가 생기는 것 같습니다 그런데 왜그런지 이해가 잘 가지 않습니다,
답변 4
0
Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'passwordEncoder';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'securityConfig': Unsatisfied dependency expressed through field 'customAuthenticationProvider';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'customAuthenticationProvider': Unsatisfied dependency expressed through field 'passwordEncoder';
nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'passwordEncoder': Requested bean is currently in creation: Is there an unresolvable circular reference?
이런 에러가 뜹니다
0
지금 SecurityConfig 와 CustomAuthenticationProvider 를 보시면 CustomAuthenticationProvider 를 빈으로 생성하는 구문이 중복되어 있습니다.
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
...
@Autowired
CustomAuthenticationProvider customAuthenticationProvider;
@Bean
public AuthenticationProvider authenticationProvider() {
return new CustomAuthenticationProvider();
}
....
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(authenticationProvider());
}
...
}
authenticationProvider() 를 통해 빈을 configure 에 설정하고 있습니다.
근데
@Autowired
CustomAuthenticationProvider customAuthenticationProvider;
으로 DI 하고 있는데 이 구문은 필요없고 사용하지도 않습니다.
이미 authenticationProvider() 로 빈을 호출 하고 있기 때문입니다.
또한 CustomAuthenticationProvider 을 보시면
@Component
public class CustomAuthenticationProvider implements AuthenticationProvider {....}
CustomAuthenticationProvider 에서도 @Component 으로 빈으로 생성하고 있습니다.
즉 이것은 스프링 시큐리티의 문제가 아니라 스프링 빈의 lifecycle 과 관련된 문제이니 관련된 내용을 좀 더 보시기 바랍니다.
일단 SecurityConfig 의
@Bean
public AuthenticationProvider authenticationProvider() {
return new CustomAuthenticationProvider();
}
을 삭제하시고
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(customAuthenticationProvider);
}
이렇게 변경해서 실행해 보시기 바랍니다.
0
https://github.com/JeongJin984/SpringSecurity/blob/master/SpringSecurity2/src/main/java/com/example/SpringSecurity2/Security/SecurityConfig.java 여기에서 Provider @Autowired 부분에서 passwordEncoder가 오류가 납니다
시큐리티 공부 버전 질문
0
175
1
[해결 방법] MethodSecurityConfig.customMethodSecurityMetadataSource() 호출하지 않는 이슈
0
185
1
AbstractSecurityInterceptor.class.beforeInvocation()를 2번 실행하는 경우
0
174
1
강의 코드가 왜이렇게 뒤죽박죽인가요...
0
249
1
메인 페이지로 접속해도 login url로 리다이렉트가 되지 않습니다..
0
235
1
파라미터값이 넘어가지 않습니다 ....
0
374
1
security filterChain 설정 질문이 있습니다.
0
330
1
소스 부분 질문 드립니다.
0
208
2
섹션4 7번 강의 문제가 있는거 같네요.
0
344
2
파일이 수시로 이름이 바껴있네요 ㄷㄷ
0
304
1
HttpSessionSecurityContextRepository를 사용안하는 문제
0
555
2
error , exception 이 잘 안됩니다.
0
278
2
thymeleaf tag 질문합니다.
0
196
2
버전업하면서 deprecated된 것들이 너무많아요
0
478
1
spring security 패치 관련
0
437
1
모바일을 사용할때 토큰말고 세션
0
845
2
DB 연동한 인가 부분에 대한 질문입니다!
0
264
1
Ajax방식도 똑같이 Session방식을 사용하는건가요?
0
307
1
Config 파일 생성 시 질문이 있습니다.
0
225
1
강사님 몇일동안 구글 검색만 100개 했는데도 이유를 모르겠습니다..
1
429
2
403 에러 뜹니다.
0
813
2
login_proc의 존재에 대한 간략한 설명입니다
0
275
1
top.html에 로그인 링크를 만들어서 로그인을 해봤습니다
0
278
2
안녕하세요. DB에 저장될 때 이해 안 가는 값이 있어서 질문드립니다!
0
189
1





