@Bean
을 제공하는 클래스의 경우, 반드시 @Configuration
을 명시해 주어야 싱글톤이 보장된다.Add this annotation to an @Configuration class to have the Spring Security configuration defined in any WebSecurityConfigurer or more likely by exposing a SecurityFilterChain bean:
WebSecurityConfigurer
에 Spring Security 구성을 정의하거나SecurityFilterChain
빈을 노출하여 정의하려면@Configuration
클래스에 이 주석을 추가하세요.
@EnableGlobalMethodSecurity
의 향상된 버전final
혹은 @NotNull
이 붙은 필드의 생성자를 자동으로 만들어준다.// @RequiredArgsConstructor 사용
@Service
@RequiredArgsConstructor
public class TestService {
private final TestRepository1 testRepository1;
private final TestRepository2 testRepository2;
}
// 생성자(Constructor) 방식
@Service
public class TestService {
private final TestRepository1 testRepository1;
private final TestRepository2 testRepository2;
@Autowired
public TestService(TestRepository1 testRepository1, TestRepository2 testRepository2) {
this.testRepository1 = testRepository1;
this.testRepository2 = testRepository2;
}
}
출처
@EnableWebSecurity 애노테이션이란?
Method Security of 스프링 시큐리티
최신 Spring Security 사용법 - SecurityFilterChain
[Spring Security] 4. 권한 처리
[Spring] 빈 등록을 위한 어노테이션 @Bean, @Configuration, @Component 차이 및 비교 - (1/2)
[스프링, Spring] @RequiredArgsConstructor 어노테이션