Spring Security WebSecurityConfigurerAdapter 가 deprecated 된 이슈해결하기
먼저 springboot 2.7.x 로 업그레이드 한다.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
Spring Boot 2.7.0 이전
/**
* SpringSecurity config
* Created by blake on 2023/01/09.
*/
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class OldSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UmsAdminService adminService;
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
// HttpSecurity 구성 생략
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService())
.passwordEncoder(passwordEncoder());
}
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
}
SpringBoot 2.7.0 이후

공식 사이트에서 권장하는 방식으로 변경해보자
/**
* SpringSecurity 5.4.x 이후 설정
* 순환 의존성을 피하기 위해 HttpSecurity만 구성
* Created by blake on 2023/01/09.
*/
@Configuration
public class SecurityConfig {
@Bean
SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
// HttpSecurity 구성 생략
return httpSecurity.build();
}
}
끝!
Last updated