You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 3.0中@EnableGlobalMethodSecurity过时,该用什么替代?

Spring Boot 3.0 替代@EnableGlobalMethodSecurity的方案

在Spring Boot 3.0(对应Spring Security 6.0及以上版本)中,@EnableGlobalMethodSecurity已被标记为过时,官方推荐使用@EnableMethodSecurity注解替代。

修改后的配置代码如下:

@Configuration
@EnableWebSecurity
@AllArgsConstructor
@EnableMethodSecurity(prePostEnabled = true)
public class SecurityConfig {
    // 你的安全配置逻辑
}

额外说明:@EnableMethodSecurity默认已经启用了prePostEnabled、securedEnabled和jsr250Enabled,如果你的需求只是开启方法级的Pre/Post注解支持,还可以进一步简化配置:

@Configuration
@EnableWebSecurity
@AllArgsConstructor
@EnableMethodSecurity
public class SecurityConfig {
    // 你的安全配置逻辑
}

内容的提问来源于stack exchange,提问作者Youcef LAIDANI

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 08:10:36