Deploy Springboot app on heroku which is using google storage services

17 views Asked by At

I have a springboot application which uses Google Cloud Storage Buckets. Now for the local development the default gcloud auth application-default login works fine but this app is to be deployed on a cloud.

Though I have tried setting up the spring configurations to use the enviroment variable GOOGLE_APPLICATION_CREDENTIALS but it keeps falling back on the default ADC (Application Default Credentials)

I have setup a token from a service created on gcp, and placed the token directly under the resource folder. setting : GOOGLE_APPLICATION_CREDENTIALS = token.json and tried giving the context root part too.

I want to use Google Cloud Storage for storing frequently accessible media resources. Is there any better option? or GCS works fine?

This is the Storage Bean :

import com.google.cloud.storage.Storage.BucketListOption;
import com.google.cloud.storage.StorageOptions;
import lombok.Getter;
import lombok.Setter;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
@Getter
@Setter
public class GcsService {

    private final Storage storage;

    public GcsService() {
        // Initialize Google Cloud Storage client
        this.storage = StorageOptions.getDefaultInstance().getService();
    }
}

Injecting this where the Storage instance is required. But when I try to print :

String googleAppCredentials = System.getenv("GOOGLE_APPLICATION_CREDENTIALS");
        if (googleAppCredentials != null) {
            System.out.println("GOOGLE_APPLICATION_CREDENTIALS is set to: " + googleAppCredentials);
        } else {
            System.out.println("GOOGLE_APPLICATION_CREDENTIALS is not set.");
        }

it runs gives the false output.

0

There are 0 answers