我一直在Intellij IDEA内开发一个弹簧引导应用程序。它现在已经完成,我即将把它发送给其他用户。仅在运行java -jar时发生循环依赖关系,而不是在使用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
你可能也有'mvn spring-boot:run'的问题,但你的配置允许循环引用(默认行为),而使用'java -jar'则有东西禁止它。 –
+0
如何控制该行为? –
+0
搜索谷歌这种类型的错误导致这个问题[使用\\EnableGlobalAuthentication或\\EnableAutoConfiguration类使用方法安全导致豆周期](https://github.com/spring-projects/spring-boot/issues/2578 )。可能与您的问题有关。你使用的是spring boot 1.2.2吗? :) –