【发布时间】:2021-02-05 11:35:13
【问题描述】:
在启动由 Gradle 构建的 Java Spring Boot 单 JAR 应用程序时,有时我会收到 BeanCreationException。我的调查表明它取决于 JAR 文件以及 Gradle 是如何构建它的。大多数情况下(但并非总是)我在 Linux 系统上构建项目时会看到异常。但我从未在 Windows 上构建的 JAR 或从 IntelliJ Idea 运行时重现该问题。
我尝试将工作 JAR 的内容与引发异常的 JAR 进行比较 - 所有 *.class 文件(包括元和资源)都是二进制相等的,唯一的区别是文件存储在 JAR 中的顺序/ZIP 存档。我还尝试在 Windows 上解压失败的 JAR,然后将其重新打包到一个新的 JAR 文件中(使用 7-zip)——应用程序启动时没有任何异常。这种奇怪的解决方法解决了这个问题,但我不想在每次在 linux 机器上构建之后都这样做。
异常建议检查循环引用,因此我尝试用 @Autowired bean 构造函数替换 @Autowired 属性以帮助我找到问题,但这并没有帮助。 stacktrace 没有提到我的任何类,所以我不知道哪个 bean 可能导致该问题。而且由于这个问题只是有时会发生并且可以通过重新打包 JAR 文件来解决,所以我不确定是否存在任何循环引用。
你能帮帮我吗?欢迎任何意见或建议。
JDK:openjdk 8u262 Gradle 5.6 版 Spring Boot 2.3.1
异常信息:
BeanCreationException: Error creating bean with name 'webConfig':
Invocation of init method failed; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'requestMappingHandlerAdapter' defined in class path resource
[org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]:
Unsatisfied dependency expressed through method 'requestMappingHandlerAdapter' parameter 0;
nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'mvcContentNegotiationManager':
Requested bean is currently in creation: Is there an unresolvable circular reference?
【问题讨论】:
标签: java spring-boot gradle