I'm integrating Google Cloud Vision API into my Spring Boot app, but I keep getting the error:
java.io.IOException: The Application Default Credentials are not available.
They are available if running in Google Compute Engine.
Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined
pointing to a file defining the credentials.
See https://developers.google.com/accounts/docs/application-default-credentials for more information.
What I Have Done :
- Created a Google Cloud Service Account and enabled Vision API.
- Placed vision-service-account.json inside src/main/resources.
- Tried different ways to set credentials in application.yml:
spring:
cloud:
gcp:
project-id: keraa-notification # My Google Cloud project ID
credentials:
location: classpath:vision-service-account.json
or
google:
cloud:
credentials:
path: vision-service-account.json
- Created a configuration class to load credentials:
2025-03-06 14:06:20 java.io.IOException: The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
2025-03-06 14:06:20 at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:127)
2025-03-06 14:06:20 at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:129)
2025-03-06 14:06:20 at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:101)
2025-03-06 14:06:20 at com.google.api.gax.core.GoogleCredentialsProvider.getCredentials(GoogleCredentialsProvider.java:70)
2025-03-06 14:06:20 at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:168)
2025-03-06 14:06:20 at com.google.cloud.vision.v1.stub.GrpcImageAnnotatorStub.create(GrpcImageAnnotatorStub.java:115)
2025-03-06 14:06:20 at com.google.cloud.vision.v1.stub.ImageAnnotatorStubSettings.createStub(ImageAnnotatorStubSettings.java:163)
2025-03-06 14:06:20 at com.google.cloud.vision.v1.ImageAnnotatorClient.<init>(ImageAnnotatorClient.java:160)
2025-03-06 14:06:20 at com.google.cloud.vision.v1.ImageAnnotatorClient.create(ImageAnnotatorClient.java:142)
2025-03-06 14:06:20 at com.google.cloud.vision.v1.ImageAnnotatorClient.create(ImageAnnotatorClient.java:133)
2025-03-06 14:06:20 at com.keraa.api.service.ImageModerationService.isImageSafe(ImageModerationService.java:21)
2025-03-06 14:06:20 at com.keraa.api.web.rest.ProductResource.createProduct(ProductResource.java:116)
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/vision-service-account.json