Spring Boot on GCP
  • Introduction
  • Getting Started
    • Google Cloud Platform
    • Cloud Shell
    • gcloud CLI
    • Hello World!
      • Cloud Shell
      • App Engine
      • Cloud Run
      • Kubernetes Engine
      • Compute Engine
      • Cloud Functions
  • Application Development
    • Development Tools
    • Spring Cloud GCP
    • Cloud Services
      • Databases
        • Cloud SQL
        • Cloud Spanner
        • Cloud Firestore
          • Datastore Mode
          • Native Mode
      • Messaging
        • Cloud Pub/Sub
        • Kafka
      • Secret Management
      • Storage
      • Cache
        • Memorystore Redis
        • Memorystore Memcached (beta)
      • Other Services
    • Observability
      • Trace
      • Logging
      • Metrics
      • Profiling
      • Debugging
    • DevOps
      • Artifact Repository
  • Deployment
    • Runtime Environments
    • Container
      • Container Image
      • Secure Container Image
      • Container Awareness
      • Vulnerability Scanning
      • Attestation
    • Kubernetes
      • Kubernetes Cluster
      • Deployment
      • Resources
      • Service
      • Health Checks
      • Load Balancing
        • External Load Balancing
        • Internal Load Balancing
      • Scheduling
      • Workload Identity
      • Binary Authorization
    • Istio
      • Getting Started
      • Sidecar Proxy
  • Additional Resources
    • Code Labs
    • Presentations / Videos
    • Cheat Sheets
Powered by GitBook
On this page
  • Dependency
  • Credentials
  • Project ID

Was this helpful?

  1. Application Development
  2. Cloud Services

Other Services

PreviousMemorystore Memcached (beta)NextObservability

Last updated 4 years ago

Was this helpful?

Spring Cloud GCP has idiomatic integrations and starters for a number of Google Cloud services, but not all services. There may be cases where you need to use a Google Cloud client library directly. In this case, you can re-use basic bootstrapping provided by the Spring Cloud GCP, so you can have a consistent way of specifying credentials for your application.

Dependency

Spring Cloud GCP already imports the , and it already has encoded the client library versions. So you can specify any Google Cloud client library without explicitly specifying a version. This is great to ensure that you are using a compatible version of a Google Cloud client library.

For example, to add Container Analysis client library:

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-containeranalysis</artifactId>
</dependency>
compile group: 'com.google.cloud', name: 'google-cloud-containeranalysis'

Credentials

You need Google Cloud credentials to access any services. produces a CredentailsProvider bean so you can re-use the same credentials.

Usually you only need a singleton instance of the client library, so it makes sense to configuring it as a Spring Bean. Most client libraries needs to be shutdown gracefully, so you should specify the destroyMethod as well:

@Bean(destroyMethod = "shutdownNow")
ContainerAnalysisClient containerAnalysisClient(CredentialsProvider credentialsProvider) throws IOException {
  return ContainerAnalysisClient.create(
    ContainerAnalysisSettings.newBuilder()
      .setCredentialsProvider(credentialsProvider).build());
}

Project ID

In rare cases, you may want to know which Project ID you are currently configured to use by default. You can find out from the .

Google Cloud Java BOM
Spring Cloud GCP Core
GcpProjectIdProvider bean