我的Spring Boot应用程序有一些问题。

Zipkin和jdbc不能共存。
通常只有一个zipkin或jdbc。

Maven依赖项:

<dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>

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


例外:

2019-07-26 18:59:14.710  WARN [service-db,,,] 30448 --- [ender@1a6dc589}] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'eurekaRibbonClientConfiguration': Unsatisfied dependency expressed through field 'clientConfig';


嵌套的异常是:

org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaClientConfigBean': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)

最佳答案

如下设置应用程序的application.yml文件中的数据源设置,

spring:
  dataSource:
    url: jdbc: mariadb://localhost:3306/test
    driverClassName: org.mariadb.jdbc.Driver
    username: test
    password: test


您可以将zipkin属性添加到POM.xml

<dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-zipkin</artifactId>
</dependency>


由于Spring的自动配置属性,可能会出现问题。

因此,如下修改数据源设置,并修改与数据源配置相关的源,以使应用程序正常工作。

myApp:
   dataSource:
     jdbc-url: jdbc:mariadb://localhost:3306/test
     driverClassName: org.mariadb.jdbc.Driver
     username: test
     password: test

10-01 15:02