2025-03-28 09:44:57.463 [main] INFO org.jeecg.JeecgSystemApplication:638 - The following 1 profile is active: "dev" 2025-03-28 09:44:58.617 [main] WARN o.s.b.w.s.c.AnnotationConfigServletWebServerApplicationContext:599 - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.jeecg.JeecgSystemApplication]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.class] cannot be opened because it does not exist 2025-03-28 09:44:58.624 [main] INFO o.s.b.a.l.ConditionEvaluationReportLoggingListener:136 - Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2025-03-28 09:44:58.646 [main] ERROR org.springframework.boot.SpringApplication:818 - Application run failed org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [org.jeecg.JeecgSystemApplication]; nested exception is java.io.FileNotFoundException: class path resource [org/springframework/security/config/annotation/authentication/configurers/GlobalAuthenticationConfigurerAdapter.class] cannot be opened because it does not exist at org.springframework.context.annotation.ConfigurationClassParser.processImports(ConfigurationClassParser.java:612) at org.springframework.context.annotation.ConfigurationClassParser.access$800(ConfigurationClassParser.java:110) at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.lambda$processGroupImports$1(ConfigurationClassParser.java:815) at java.base/java.util.ArrayList.forEach(ArrayList.java:1597) at org.springframework.context.annotation.ConfigurationClassParser$DeferredImportSelectorGroupingHandler.processGroupImpor
时间: 2025-07-13 21:43:26 浏览: 3
<think>好的,用户遇到了Spring Boot应用启动时出现的BeanDefinitionStoreException异常,提示缺少GlobalAuthenticationConfigurerAdapter类。我需要先分析这个问题的原因,然后给出解决方案。
首先,GlobalAuthenticationConfigurerAdapter是Spring Security中的一个类,通常用于全局的身份验证配置。在Spring Boot 2.7及更高版本中,Spring团队开始逐步弃用一些旧的配置类,转向使用基于组件扫描的配置方式,或者Lambda风格的DSL配置。因此,如果用户的项目升级了Spring Boot版本,可能会遇到这个类被移除的情况,导致应用启动失败。
接下来,我需要确定用户的项目中使用的Spring Boot和Spring Security版本。如果用户使用的是较新的版本,比如Spring Boot 3.0以上,那么GlobalAuthenticationConfigurerAdapter已经被移除,这时候需要调整配置方式。可能的解决方案包括降级Spring Security版本,或者更新配置代码以适配新版本。
另外,检查依赖管理是否正确也很重要。可能用户的项目中引入了不同版本的Spring Security模块,导致依赖冲突。需要确保所有Spring相关的依赖版本一致,并且与Spring Boot的版本兼容。
然后,考虑配置类的调整。如果用户之前使用的是继承GlobalAuthenticationConfigurerAdapter的自定义配置类,可以改为使用SecurityFilterChain来定义安全配置。例如,使用@Bean方法来配置HttpSecurity,设置身份验证管理器和密码编码器等。
最后,可能需要清理和重新构建项目,确保所有依赖正确下载,没有残留的旧版本类路径文件导致问题。
总结下来,解决方案可能包括:检查并调整依赖版本,更新安全配置方式,清理构建缓存等步骤。需要一步步引导用户进行操作,并提醒他们在修改后重新启动应用测试效果。</think>### Spring Boot启动时BeanDefinitionStoreException异常解决方案
**问题原因分析**
出现`BeanDefinitionStoreException`异常且提示缺少`GlobalAuthenticationConfigurerAdapter`类,通常与以下原因相关:
1. **Spring Security版本冲突**:在Spring Boot 2.7+或Spring Security 5.7+版本中,`GlobalAuthenticationConfigurerAdapter`已被标记为`@Deprecated`,后续版本直接移除了该类[^1]。
2. **依赖配置错误**:项目中可能同时存在旧版Spring Security和新版Spring Boot的依赖,导致类路径不兼容。
3. **自定义安全配置未更新**:代码中仍在使用继承`GlobalAuthenticationConfigurerAdapter`的配置类。
**解决方案步骤**
1. **检查依赖版本**
在`pom.xml`或`build.gradle`中确认Spring Boot与Spring Security版本对应关系:
```xml
<!-- 示例:Spring Boot 2.7.x对应Spring Security 5.7.x -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.18</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
```
如果使用Spring Boot 3.x,需将Spring Security升级到6.x,并改用新配置方式[^1]。
2. **更新安全配置方式**
将原有继承`GlobalAuthenticationConfigurerAdapter`的配置类替换为基于`SecurityFilterChain`的配置:
```java
@Configuration
public class SecurityConfig {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeRequests(auth -> auth
.anyRequest().authenticated()
)
.formLogin(withDefaults());
return http.build();
}
@Bean
public PasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
}
```
3. **清理构建缓存**
执行以下操作确保依赖更新生效:
```bash
# Maven项目
mvn clean install -U
# Gradle项目
gradle clean build --refresh-dependencies
```
**典型错误日志示例**
```
Caused by: java.lang.ClassNotFoundException: org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter
```
**验证结果**
启动应用后,若控制台不再报错且能正常加载安全配置,则问题已解决。
阅读全文
相关推荐



















