如何禁用 Google Cloud Platform 集成?

Luk*_*101 5 java spring-boot google-cloud-platform

我的 POM 文件中有这两个依赖项:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-gcp-starter-trace</artifactId>
</dependency>
<dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-gcp-starter-logging</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我想在某些配置文件中禁用这些 GCP 功能。我需要在本地测试我的应用程序,但 GCP 一直在妨碍我。

Mic*_*iel 8

Spring 在设置应用程序时依赖于自动配置。在许多情况下,它会扫描类路径中的某些依赖项,如果存在,则会执行自动配置。大多数时候,可以通过提供特定条件来绕过自动配置。

在遍历 Spring Cloud gcp 模块时,我遇到了StackdriverLoggingAutoConfiguration类 ( source ) 和StackdriverTraceAutoConfiguration( source )。

StackdriverLoggingAutoConfiguration 有条件ConditionalOnProperty(value="spring.cloud.gcp.logging.enabled", matchIfMissing=true),而 StackdriverTraceAutoConfiguration 有条件@ConditionalOnProperty(value="spring.cloud.gcp.trace.enabled", matchIfMissing=true)

我不完全确定这些属性是否与您使用的模块的自动配置相关,但您可以通过将以下内容添加到您的 application-{localprofile}.properties 来禁用日志记录:

spring.cloud.gcp.logging.enabled=false
spring.cloud.gcp.trace.enabled=false
Run Code Online (Sandbox Code Playgroud)


小智 5

因为问题是

如何禁用 Google Cloud Platform 集成

我建议只更改我们的配置

spring:
  cloud:
    gcp:
      core:
        enabled: false
Run Code Online (Sandbox Code Playgroud)

在我们的项目中禁用与 Spring Cloud GCP 相关的所有内容应该就足够了

接受的答案告诉您如何禁用我们项目中使用的部分 GCP 功能。如果您有很多(日志记录、PubSub、存储……),则禁用所有这些可能会很麻烦。这是一次禁用所有这些的快捷方式;-)