春季云:正在创建请求的bean:是否存在不可解析的循环引用?

时间:2018-06-25 16:28:40

标签: spring spring-boot spring-cloud spring-cloud-netflix

我有一个要在其中添加Spring Cloud Netlix Eureka的应用程序。

我已将此服务发现添加到其他2个服务中而没有出现问题。在第三项服务中,它是更复杂的一项,添加后:

Spring云依赖性

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

bootstrap.properties,具有应用程序名称

spring.application.name=my-app

与application.properties中的Eureka相关的配置

eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
eureka.client.register-with-eureka=true
eureka.client.fetch-registry=true
eureka.instance.instance-id=${spring.application.name}:${random.int}
eureka.instance.hostname=localhost

使Eureka客户端对Application类一无所获

@EnableEurekaClient

启动应用后,出现以下错误:

2018-06-25 18:22:31.229 ERROR 7862 --- [ost-startStop-1] o.s.b.web.embedded.tomcat.TomcatStarter  : Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. Message: Error creating bean with name 'servletEndpointRegistrar' defined in class path resource [org/springframework/boot/actuate/autoconfigure/endpoint/web/ServletEndpointManagementContextConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.endpoint.web.ServletEndpointRegistrar]: Factory method 'servletEndpointRegistrar' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'healthEndpoint' defined in class path resource [org/springframework/boot/actuate/autoconfigure/health/HealthEndpointConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.health.HealthEndpoint]: Factory method 'healthEndpoint' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration': Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthIndicatorAutoConfiguration$$EnhancerBySpringCGLIB$$f4aa1064]: Constructor threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.jdbc.DataSourceInitializerInvoker': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource': Post-processing of FactoryBean's singleton object failed; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'scopedTarget.dataSource': Requested bean is currently in creation: Is there an unresolvable circular reference?

我不确定为什么创建数据源时会出现问题。 与其他服务的唯一区别是该服务连接到postgres数据库。

在“ DataSourceHealthIndicatorAutoConfiguration”类中,我已经在此处指出了问题:

enter image description here

但是,我仍然不确定为什么只在类路径上使用弹簧云。

此外,我怀疑这是否相关,因为删除它并不能解决问题,但我还添加了一个新的Bean:

@LoadBalanced
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
  return builder.build();
}

在类中像这样使用

private final RestTemplate restTemplate;

@Autowired
public AudienceConsoleAudienceFetcher(RestTemplate restTemplate) {
  this.restTemplate = restTemplate;
}

这取代了我以前在同一堂课上的内容:

private RestTemplate restTemplate = new RestTemplate();

编辑:

这是pom.xml和Application类:https://gist.github.com/nWidart/1f3a635d6d392afe68d09603c260ed04

谢谢!

0 个答案:

没有答案