我一直在Intellij IDEA内部开发一个spring-boot应用程序。它现在已经完成,我即将把它发送给其他用户。
我使用mvn clean install
构建它并尝试使用java -jar target/my-app.jar
启动内置的-jar文件。
令我惊讶的是,它失败了一个例外(很难读,但至少被切成几行)
Exception encountered during context initialization - cancelling refresh attempt:
org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'userController':
Unsatisfied dependency expressed through field 'userClient';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name '***.client.userclient.UserClient':
FactoryBean threw exception on object creation;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration':
Unsatisfied dependency expressed through method 'setConfigurers' parameter 0;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'webMvcConfig':
Unsatisfied dependency expressed through field 'authenticationInterceptor';
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException:
Error creating bean with name 'authenticationInterceptor':
Unsatisfied dependency expressed through field 'authenticationClient';
nested exception is org.springframework.beans.factory.BeanCreationException:
Error creating bean with name '***.client.authenticationclient.AuthenticationClient':
FactoryBean threw exception on object creation;
nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException:
Error creating bean with name 'mvcResourceUrlProvider':
Requested bean is currently in creation: Is there an unresolvable circular reference?
我也得到了一些关于依赖的ascii艺术
***************************
APPLICATION FAILED TO START
***************************
Description:
The dependencies of some of the beans in the application context form a cycle:
| userController (field ****.client.userclient.UserClient ****.controller.user.UserController.userClient)
↑ ↓
| ****.client.userclient.UserClient
↑ ↓
| org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration$EnableWebMvcConfiguration
↑ ↓
| webMvcConfig (field ****.AuthenticationInterceptor ****.WebMvcConfig.authenticationInterceptor)
↑ ↓
| authenticationInterceptor (field ****.client.authenticationclient.AuthenticationClient ****.AuthenticationInterceptor.authenticationClient)
↑ ↓
| ****.client.authenticationclient.AuthenticationClient
↑ ↓
| mvcResourceUrlProvider
└─────┘
所以我尝试使用mvn spring-boot:run
运行它并且它有效!
我的印象是,与java -jar
和mvn spring-boot:run
一起运行会是一样的。我错过了什么?
我想我可以修复循环依赖关系,但现在困扰我的是为什么这两个跑者不同。
感谢。
答案 0 :(得分:1)
[添加为无法评论的答案]
不确定actor: UnitTester
modules:
enabled:
- Asserts
- Laravel5:
part: ORM
- \Helper\Unit
和java -jar
的跑步者为何不同。添加mvn spring-boot:run
对于@Lazy
的跑步者是有用的。
A.java
java -jar
B.java
@Autowired
@Lazy
//setter injection
public void setB(B b) {
this.b = b;
}
答案 1 :(得分:0)
春天是个问题,请参见
https://github.com/spring-projects/spring-boot/issues/6045
https://github.com/spring-projects/spring-framework/issues/18879
临时拐杖解决方案
在application.properties中设置或以其他方式设置:
spring.main.lazy-initialization=true