【问题标题】:GCP secretmanager from Spring Boot throws ConverterNotFoundExceptionSpring Boot 中的 GCP secretmanager 抛出 ConverterNotFoundException
【发布时间】:2021-08-20 11:41:48
【问题描述】:

我正在尝试从部署了 Spring Boot 应用程序的 appengine 访问 gcp secreetmanager,但我不断收到 org.springframework.core.convert.ConverterNotFoundException:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'com.example.email.EMailServiceApplication$HelloWorldController': Injection of autowired dependencies 
failed; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter 
found capable of converting from type [com.google.protobuf.ByteString$LiteralByteString] to type [java.lang.String]

当前的 pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.0</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>email-service</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>E-Mail Service</name>
    <description>E-Mail Service für arktum</description>
    <properties>
        <java.version>11</java.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-gcp-dependencies</artifactId>
                <version>1.2.8.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter-secretmanager</artifactId>
            <version>2.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>2.4.0</version>
                <configuration>
                    <version>1</version>
                    <projectId>GCLOUD_CONFIG</projectId>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

还有主类:

@SpringBootApplication
public class EMailServiceApplication {

  public static void main(String[] args) {
    SpringApplication.run(EMailServiceApplication.class, args);
  }

  @RestController
  class HelloWorldController {

    @Value("${sm://greeting-prod}")
    private String greeting;

    @GetMapping("/")
    public String hello() {
      return this.greeting;
    }
  }
}

没有额外的配置属性,例如应用程序.properties。是否缺少任何依赖项?

【问题讨论】:

  • 在将 spring boot 从 2.1.0 升级到 2.5.1 后,我遇到了一个非常相似的问题。你找到解决办法了吗?
  • 从 2.4.5 升级到 2.5.1 后相同
  • @Tom 这是一个已知问题。在解决之前,我们必须坚持使用 2.4.7。

标签: spring-boot google-secret-manager


【解决方案1】:

根据https://github.com/GoogleCloudPlatform/spring-cloud-gcp/issues/490Cloud GCP 与 Spring Boot 2.5.x 不兼容:

我们尚未将 Spring Cloud GCP 升级到 Spring Boot 2.5 兼容性 (#472)。本周我将研究升级阻止程序。

如果你使用Spring Initializr,Spring Boote 2.5.x 和 GCP 的组合被阻止 - 你必须坚持使用 2.4.7,它工作得很好。

【讨论】:

  • 这是 16 天前修复的。现在只需将您的属性更新为:2.0.4
【解决方案2】:

这是由于 https://github.com/GoogleCloudPlatform/spring-cloud-gcp/issues/490 错误造成的。

此缺陷现已修复。请将您的 GCP 依赖项升级到 2.0.4

        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-dependencies</artifactId>
            <version>2.0.4</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

【讨论】:

    【解决方案3】:

    bug 已修复。将 spring-cloud-gcp-dependencies 更新到 2.0.5。

    build.gradle 演示:

    buildscript {
        ext {
            springBootVersion = '2.5.6'
            googleCloudVersion = '2.0.5'
        }
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath "org.springframework.boot:spring-boot-gradle-plugin:$springBootVersion"
            classpath "com.google.cloud:spring-cloud-gcp-dependencies:$googleCloudVersion"
        }
    }
    
    dependencies {
        implementation("com.google.cloud:spring-cloud-gcp-starter:$googleCloudVersion")
        implementation("com.google.cloud:spring-cloud-gcp-starter-secretmanager:$googleCloudVersion")
        // ...
    }
    
    

    【讨论】:

      猜你喜欢
      • 2017-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-05
      • 2016-09-26
      • 2019-09-19
      • 2018-11-12
      • 2018-10-04
      相关资源
      最近更新 更多