WebSecurityConfigurerAdapter不被推荐
时间: 2024-01-25 14:04:01 浏览: 25
WebSecurityConfigurerAdapter不被推荐使用是因为它已经过时并且不再是Spring Security的首选配置方式。相比于使用WebSecurityConfigurerAdapter,Spring Security 5.4 引入了新的接口WebSecurityCustomizer,可以更灵活地自定义WebSecurity。使用WebSecurityCustomizer时,我们可以在Spring Security的配置类中实现该接口,并通过回调方法configure来定制WebSecurity的行为。
引用中的示例代码展示了使用WebSecurityConfigurerAdapter的配置,这种方式在Spring Security 5.4及以后的版本中被认为是不推荐的。引用中的示例代码展示了一个更现代化的配置方式,使用WebSecurityConfigurerAdapter的替代方案。
相关问题
WebSecurityConfigurerAdapter不能被继承
WebSecurityConfigurerAdapter可以被继承。它是一个Spring Security提供的方便类,用于帮助我们自定义Web安全配置。我们可以通过继承WebSecurityConfigurerAdapter类来自定义我们的安全配置,并重写configure方法来配置特定的安全规则。
重写WebSecurityConfigurerAdapter不生效
当重写`WebSecurityConfigurerAdapter`的方法不生效时,可能有以下几个原因:
1. 检查是否正确继承了`WebSecurityConfigurerAdapter`类,并且使用了`@Configuration`注解标记该类作为配置类。
2. 确保重写的方法名和参数列表与父类中的方法一致。例如,如果要重写`configure(WebSecurity web)`方法,确保方法名和参数列表都正确。
3. 检查是否在重写的方法上使用了`@Override`注解,确保正确覆盖了父类的方法。
4. 确保重写的方法中的逻辑正确。例如,在`configure(WebSecurity web)`方法中,使用`web.ignoring().antMatchers()`方法来配置需要忽略的静态资源路径。
如果以上步骤都正确,但重写的方法仍然不生效,可以尝试重启应用程序或清除缓存,以确保配置的更新生效。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)