【问题标题】:部署到 GKE 时应用程序启动失败,显示“GcpContextAutoConfiguration”已排除
【发布时间】:2021-09-20 08:51:20
【问题描述】:

我有一个应用程序,当我部署到 GCP 时,它无法启动,但它在我的本地使用 docker 运行良好。我不知道如何解决这个问题,我需要在我的属性文件中包含任何内容吗?

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 1 of constructor in org.springframework.cloud.gcp.autoconfigure.pubsub.GcpPubSubAutoConfiguration required a bean of type 'org.springframework.cloud.gcp.core.GcpProjectIdProvider' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)

The following candidates were found but could not be injected:
    - Bean method 'gcpProjectIdProvider' in 'GcpContextAutoConfiguration' not loaded because auto-configuration 'GcpContextAutoConfiguration' was excluded
    - Bean method 'gcpProjectIdProvider' in 'GcpContextAutoConfiguration' not loaded because auto-configuration 'GcpContextAutoConfiguration' was excluded
    - Bean method 'gcpProjectIdProvider' in 'GcpContextAutoConfiguration' not loaded because auto-configuration 'GcpContextAutoConfiguration' was excluded


Action:

Consider revisiting the entries above or defining a bean of type 'org.springframework.cloud.gcp.core.GcpProjectIdProvider' in your configuration.

我已包含以下属性

spring.cloud.gcp.pubsub.enabled: true
spring.cloud.gcp.config.enabled: true
spring.cloud.gcp.security.iap.enabled: true
#I DO NOT have this line below
#spring.autoconfigure.exclude: org.springframework.cloud.gcp.autoconfigure.core.GcpContextAutoConfiguration

在我的 pom 中,我也包含了这些

    <dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>${spring-boot-release.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gcp-dependencies</artifactId>
            <version>${spring-cloud-gcp.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-gcp-pubsub</artifactId>
    </dependency>

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

    <dependency>
        <groupId>org.springframework.integration</groupId>
        <artifactId>spring-integration-core</artifactId>
    </dependency>
<dependencies>

有人可以帮忙吗?

【问题讨论】:

    标签: google-cloud-platform google-cloud-pubsub spring-cloud-gcp


    【解决方案1】:

    尝试将 Spring Cloud GCP 启动器添加到配置身份验证和项目设置的依赖项中:

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

    另外,如果您指定了spring-cloud-gcp-starter-pubsub 依赖项,则无需添加spring-cloud-gcp-pubsub,因为它已经包含在第一个依赖项中。

    【讨论】:

      【解决方案2】:

      排除GcpContextAutoConfiguration 的最可能原因是您部署的属性在某处有spring.cloud.gcp.core.enabled=false

      要准确检查 Spring Boot 自动配置的内容及其原因,请将 -Ddebug=true 传递给您的 Java 进程(如果从 Maven 运行,请将其传递为 -Dspring-boot.run.jvmArguments="-Ddebug=true"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-08-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-20
        • 1970-01-01
        • 2018-08-21
        • 1970-01-01
        相关资源
        最近更新 更多