Spring 应用程序无法启动,因为 Fabric8ConfigReloadAutoConfiguration 需要单个 bean,但找到了 2 个

问题描述 投票:0回答:1

背景:

起点是在 Spring Boot 2.7.14 和 Spring Cloud 2021.0.8 之上开发的微型。使用 K8s 1.25,应用程序启动没有任何问题。

升级到 Spring Boot 3.1.5 和 Spring Cloud 2022.0.3 后,出现了一些问题,我遇到了以下问题:

{
"timestamp": "2023-12-20T10:43:37.844Z",
"severity": "error",
"message": "***************************APPLICATION FAILED TO START***************************Description:\n\nParameter 2 of method configMapPropertyChangeEventWatcher in org.springframework.cloud.kubernetes.fabric8.config.reload.Fabric8ConfigReloadAutoConfiguration required a single bean, but 2 were found:\n\t- configDataConfigMapPropertySourceLocator: a programmatically registered singleton\t- configMapPropertySourceLocator: defined by method 'configMapPropertySourceLocator' in class path resource [org/springframework/cloud/kubernetes/fabric8/config/Fabric8BootstrapConfiguration.class]\n\n\nAction:\n\nConsider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed\n ",
"service_id": "databasefe",
"metadata": {
    "function": "DBFE"
},
"version": "1.2.0"}

所以事情是这样的:

最后一个项目符号意味着我们替换了旧的

bootstrap.properties
文件,如下所示:

# Bootstrap settings for ConfigMap
spring.application.name=${SERVICE_NAME:my-app}

使用新的

application.properties
文件:

spring.config.import=optional:kubernetes:
spring.cloud.kubernetes.config.name=${SERVICE_NAME:my-app}

现在我们有

Fabric8ConfigReloadAutoConfiguration
类,两个 bean 存在歧义问题,由
org.springframework.cloud.kubernetes.fabric8
类型的
Fabric8ConfigMapPropertySourceLocator
提供,我没有任何直接控制权,既不能将其中一个标记为主要的,也不能限定其中任何一个.

因此,我的问题是,升级后发生了什么变化,或者我应该注意什么,从而引发了我们以前没有的行为。

这是管理相关依赖项的 pom 的相关部分:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <artifactId>java-dependencies-layer</artifactId>
  <packaging>jar</packaging>

  <name>product java dependencies layer</name>
  <description>base layer for java dependencies</description>

  <parent>
    <groupId>com.company.product</groupId>
    <artifactId>java-dependencies-aggregator</artifactId>
    <version>${revision}</version>
  </parent>

  <properties>

    <!-- Project encoding and Java version -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>17</java.version>

    <revision>1.0.0-dummy</revision>

    <!-- sonarqube -->
    <sonar.host.url>https://sonarqube.lmera.ericsson.se</sonar.host.url>
    <sonar.sources>/usr/src/app/src/main</sonar.sources>
    <sonar.tests>/usr/src/app/src/test</sonar.tests>
    <sonar.coverage.jacoco.xmlReportPaths>/usr/src/app/target/site/jacoco/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>

  </properties>

  <dependencies>
    

    <!-- 3pp dependencies start -->

    <!-- Spring Framework dependencies start -->
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.apache.logging.log4j</groupId>
          <artifactId>log4j-to-slf4j</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-log4j2</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-stream</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-stream-binder-kafka</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-kubernetes-fabric8-config</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-starter-bootstrap</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
      <exclusions>
        <exclusion>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-jetty</artifactId>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty.http2</groupId>
      <artifactId>http2-server</artifactId>
    </dependency>
    <dependency>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-jmx</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.ws</groupId>
      <artifactId>spring-ws-core</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.integration</groupId>
      <artifactId>spring-integration-sftp</artifactId>
    </dependency>
    <!-- Spring Framework dependencies end -->
    
    <!-- 3pp dependencies end -->
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <mainClass>Application</mainClass>
          <layers>
            <enabled>true</enabled>
            <includeLayerTools>true</includeLayerTools>
          </layers>
        </configuration>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>

    </plugins>
  </build>
</project>

可能与:Spring Cloud Kubernetes 应用程序无法启动:

如有任何帮助,我们将不胜感激。

spring-boot spring-cloud fabric8 fabric8-kubernetes-client
1个回答
0
投票

我们在这里找到了此问题的解决方案:Stackoverflow:Spring Cloud Kubernetes 应用程序无法启动:。我们无法删除 application.properties,因为我们使用它来指示配置映射的名称。排除pom.xml中的spring-cloud-starter-bootstrap,我们解决了这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.