-
@RequiredArgsConstructor를 사용 못하는 경우개발/Spring 2023. 12. 24. 01:13
같은 타입의 빈을 복수로 정의했을 때는 모호성 에러가 발생하는데 이 때 생성자를 직접 정의해 객체를 주입할 때 @Qualifier를 사용해서 컴포넌트를 명시한다.
public SecurityConfig( CustomUserDetails customUserDetails, PasswordEncoder passwordEncoder, AuthenticationDetailsSource authenticationDetailsSource, @Qualifier("customAuthSuccessHandler") AuthenticationSuccessHandler successHandler, @Qualifier("customAuthFailureHandler") AuthenticationFailureHandler failureHandler) { this.customUserDetails = customUserDetails; this.passwordEncoder = passwordEncoder; this.authenticationDetailsSource = authenticationDetailsSource; this.authenticationSuccessHandler = successHandler; this.authenticationFailureHandler = failureHandler; } ... @Component("customAuthSuccessHandler") public class CustomAuthenticationSuccessHandler extends SimpleUrlAuthenticationSuccessHandler { ... } @Component("customAuthFailureHandler") public class CustomAuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler { ... }
'개발 > Spring' 카테고리의 다른 글
[Security OAUTH2.0] Credential client, Public client (0) 2024.02.01 [Spring Security5] 인가 예외(접근 거부) (1) 2023.12.23 [Spring Security5] Config에서 defaultSuccessUrl(), successHandler()의 순서 문제 (0) 2023.12.22 [Spring Security5] SecurityContext에 가졌던 작은 오해 (0) 2023.12.18 [Spring security5] 인증/인가에 대한 간략한 흐름 (0) 2023.12.16