在较新版本的 Spring Security 中,WebSecurityConfigurerAdapter 类已被弃用并删除。什么可以代替它?我正在使用视频课程教授Spring Security,在视频课程中有一个旧版本的Spring Boot,或者更确切地说是版本2.5.1,而我有版本Spring Boot 3.2.3,我如何替换这段代码以便它在我正在使用的版本上的工作方式相同吗? 包 ru.alishov.springcourse.FirstSecurityApp.config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import ru.alishov.springcourse.FirstSecurityApp.services.PersonDetailsService;
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
private final PersonDetailsService personDetailsService;
@Autowired
public SecurityConfig(PersonDetailsService personDetailsService)
{ this.personDetailsService = personDetailsService; }
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception
{ auth.userDetailsService(personDetailsService); }
@Bean
public PasswordEncoder getPasswordEncoder()
{ return NoOpPasswordEncoder.getInstance(); }
}
在 Spring Security 5.7.0 中,Spring 弃用了 WebSecurityConfigurerAdapter。
它鼓励基于组件的安全配置。