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

升级Spring Boot Thin后IntelliJ启动报NoSuchBeanDefinition等异常求助

解决Spring Boot Thin插件在IntelliJ IDEA Services启动时的CGLIB/Bean定义异常

我之前碰到过一模一样的问题,这是Spring Boot Thin插件的类加载机制和IntelliJ IDEA启动环境(尤其是搭配Spring DevTools时)的冲突导致的,给你几个有效的解决思路:

方法1:禁用Spring DevTools

Spring DevTools的重启类加载器和Thin插件的动态类加载器很容易发生冲突,导致类访问权限问题和Bean定义异常:

  • 临时注释掉pom.xml中的DevTools依赖:
<!--<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
</dependency>-->
  • 或者在application.properties中关闭重启功能:
spring.devtools.restart.enabled=false
  • 也可以在IntelliJ的启动配置中,去掉Enable auto build选项,避免DevTools触发类重新加载。

方法2:使用Maven命令启动应用(推荐)

既然java -jar启动正常,我们可以让IDEA通过Maven命令来启动应用,这样类加载环境和打包后一致:

  1. 在IntelliJ中打开Run/Debug Configurations
  2. 新建一个Maven配置
  3. 在Command line中填入:spring-boot:run
  4. 如果需要调试,添加JVM参数:spring-boot:run -Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005",然后通过远程调试连接到5005端口。

方法3:调整Spring Boot Thin插件的类加载配置

在pom.xml的Thin插件中添加类加载器相关配置,强制使用统一的类加载上下文:

<plugin>
    <groupId>org.springframework.boot.experimental</groupId>
    <artifactId>spring-boot-thin-layout</artifactId>
    <version>${spring-boot-thin.version}</version>
    <configuration>
        <properties>
            <thin.classloader>true</thin.classloader>
        </properties>
    </configuration>
</plugin>

问题原因说明

Spring Boot Thin插件的核心是动态下载并加载依赖,它会使用自定义的类加载器来管理这些依赖。而IntelliJ IDEA的Services面板启动应用时,默认会结合自身的类加载机制(加上DevTools的重启类加载器),导致RepositorySchemaController这样的类被两个不同的类加载器加载:父类由Thin的类加载器加载,CGLIB生成的子类由应用类加载器加载,从而触发IllegalAccessError(类加载器不同导致访问权限被拒绝)。同时类加载器冲突还会引发NoSuchBeanDefinitionException,因为Bean的定义在不同的类加载上下文无法被识别。

而使用java -jar启动时,所有类都由Thin插件的类加载器统一管理,不存在类加载器冲突,所以应用能正常运行。

内容的提问来源于stack exchange,提问作者Space Cadet

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.07 22:12:54