新老版本写法对比
新版本
public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception {
}
老版本
@Configuration
@EnableWebSecurity
public class MyWebSecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().permitAll();
}
}
爽点在于哪里
新版本支持DSL,也就是HttpSecurity 配置方式上的不同,但其实更爽的是不需要重写,而是采用注入bean的方式,有啥区别呢,一个是spring的方向问题,更趋向模块组件化,配置化,另一个是采用重写,有一定的概率在后续升级会隐藏掉一些新功能,对于我们来说,就是代码变简洁了。