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

添加@SpringBootApplication注解报错,排除SecurityAutoConfiguration时提示Name expected

问题排查与解决
  • 依赖未引入或类路径错误
    如果项目没有引入Spring Security依赖,却尝试排除SecurityAutoConfiguration,IDE会找不到这个类,触发“Name expected”错误。
    解决:要么在pom.xml(Maven)或build.gradle(Gradle)中添加Spring Security依赖,要么移除exclude参数里的SecurityAutoConfiguration.class(若项目不需要Spring Security)。

  • 注解语法或类名拼写错误
    检查@SpringBootApplication注解的语法:确认SecurityAutoConfiguration类名拼写完全正确,注解内的大括号、等号等符号格式合规(正确写法示例:@SpringBootApplication(exclude = {SecurityAutoConfiguration.class}))。若类名写错或符号使用错误,会导致IDE无法识别。
    解决:核对类名拼写,修正注解内的语法问题。

  • IDE缓存干扰
    IDE缓存异常可能导致代码识别错误,明明语法正确却报“Name expected”。
    解决:清理IDE缓存并重启(比如IntelliJ IDEA可通过File -> Invalidate Caches... -> Invalidate and Restart操作),之后重新构建项目。

  • Spring Boot版本兼容问题
    不同版本的Spring Boot中,SecurityAutoConfiguration的包路径或类名可能存在差异,若使用了错误的全类名,会导致找不到类。
    解决:核对当前Spring Boot版本对应的SecurityAutoConfiguration全类名(标准路径为org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration),确保包路径和类名完全匹配。

内容的提问来源于stack exchange,提问作者Ivan Kajam

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.18 09:05:28