반응형
WebSecurityConfigurerAdapter Deprecated 해결하기
새로 프로젝트를 만들고 이전처럼 WebSecurityConfigurerAdapter 클래스를 상속받아 SecurityConfig 클래스를 만들었는데 아래와 같은 경고가 발생했다.
'org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter' is deprecated

공식 문서를 찾아보니 아래와 같이 설명되어있는 것을 확인할 수 있었다.
In Spring Security 5.7.0-M2 we deprecated the WebSecurityConfigurerAdapter, as we encourage users to move towards a component-based security configuration.
In Spring Security 5.4 we introduced the ability to configure HttpSecurity by creating a SecurityFilterChain bean.
Spring Security 5.7.0 버전부터는 @Component 기반의 설정을 지향하기 위해 configure 함수를 상속받는 것이 아닌 @Bean으로 직접 등록해줘야 한다고 한다.
아래와 같이 configure 함수를 통해 설정했던 것을 @Bean으로 직접 만들어주면 해결된다.
@Configuration
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/").permitAll()
.anyRequest().authenticated();
return http.build();
}
@Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().antMatchers("/ignore1", "/ignore2");
}
}
참고자료
반응형
'Tips > Spring Boot' 카테고리의 다른 글
[Spring Boot] Process 'Gradle Test Executor 1' finished with non-zero exit value 1 해결법 (0) | 2022.10.30 |
---|---|
[Spring Boot] @DataJpaTest에서 JPAQueryFactory Bean 등록 안될때 (0) | 2022.10.27 |
[Spring Boot] OSIV (Open Session In View) 비활성화 후 JPA 조회 안될 때 (0) | 2022.09.21 |
[Spring] 빌드 시 invalid source release: XX 뜰 때 (0) | 2022.08.31 |
[Spring Boot] Infinite recursion (StackOverflowError) 오류 날 때 (0) | 2022.02.23 |