irpas技术客

Consider defining a bean of type ‘com.netflix.discovery.AbstractDiscoveryClientO

未知 7670

2021-06-02 07:07:08.545 INFO 4044 --- [ main] com.example.client.ClientApplication : Starting ClientApplication using Java 15 on DESKTOP-JQL00D4 with PID 4044 (C:\Users\xxx\workspace-spring-tool-suite-4-4.8.1.RELEASE\client\target\classes started by xxx in C:\Users\xxx\workspace-spring-tool-suite-4-4.8.1.RELEASE\client) 2021-06-02 07:07:08.555 INFO 4044 --- [ main] com.example.client.ClientApplication : No active profile set, falling back to default profiles: default 2021-06-02 07:07:10.045 INFO 4044 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=20f69ff4-2081-3357-9eb0-d6af76333385 2021-06-02 07:07:10.945 WARN 4044 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration': Unsatisfied dependency expressed through field 'optionalArgs'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.netflix.discovery.AbstractDiscoveryClientOptionalArgs<?>' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 2021-06-02 07:07:10.969 INFO 4044 --- [ main] ConditionEvaluationReportLoggingListener : Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2021-06-02 07:07:11.013 ERROR 4044 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPLICATION FAILED TO START *************************** Description: Field optionalArgs in org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration required a bean of type 'com.netflix.discovery.AbstractDiscoveryClientOptionalArgs' that could not be found. The injection point has the following annotations: - @org.springframework.beans.factory.annotation.Autowired(required=true) Action: Consider defining a bean of type 'com.netflix.discovery.AbstractDiscoveryClientOptionalArgs' in your configuration.

在配置eureka client时,启动应用后,一直报错,错误信息如上。错误信息提示缺少这样一个class: AbstractDiscoveryClientOptionalArgs,并且还有?No active profile set, falling back to default profiles的提示。

查看解决办法: 在创建project时,只是选择了如下eureka依赖:

<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>

而eureka client 依赖的com.netflix.discovery.AbstractDiscoveryClientOptionalArgs 最终依赖于?spring-web-5.3.4.jar(https://·/article/932.htm?给出了详细解释)

于是我在pom.xml的依赖管理中添加了如下依赖,然后在STS中右击 --> maven --> update project,但是应用仍然启动不起来,报相同的错。

<dependency> ?? ??? ?<groupId>org.springframework.boot</groupId> ?? ??? ?<artifactId>spring-boot-starter-web</artifactId> </dependency>

把整个项目删除,重新新建工程,在新建时选择eureka client 和 spring-web,再启动,一切正常了。

对比了新建的项目,我发现上面的?spring-boot-starter-web依赖需要添加到pom.xml的<project>标签下的<dependencies>中,而不能添加到<dependencyManagement>下的<dependencies>中。那么问题来了,这两处依赖有什么不同呢?


1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,会注明原创字样,如未注明都非原创,如有侵权请联系删除!;3.作者投稿可能会经我们编辑修改或补充;4.本站不提供任何储存功能只提供收集或者投稿人的网盘链接。

标签: #Consider #defining #a #bean #of #type