google-cloud-platformpublish-subscribecredentials

How to specify the GCP Credential Location in application.properties file (for using the Pub/Sub in GCP)?


This seems straightforward to do that passing the Service Account key file (generated from the GCP console) by specifying the file location in the application.properties file. However, I tried all the following options:

1. spring.cloud.gcp.credentials.location=file:/home/my_user_id/mp6key.json
2. spring.cloud.gcp.credentials.location=file:src/main/resources/mp6key.json
3. spring.cloud.gcp.credentials.location=file:./main/resources/mp6key.json
4. spring.cloud.gcp.credentials.location=file:/src/main/resources/mp6key.json

It all ended up with the same error:

java.io.FileNotFoundException: /home/my_user_id/mp6key.json (No such file or directory)

Could anyone advise where I should put the key file and then how should I specify the path to the file properly?

The same programs run successfully in Ecplise with messages published and subscribed using the Pub/Sub processing from GCP (using the Project Id/Service Account key generated in GCP), but now stuck with the above issue after deployed to run on GCP.


Solution

  • Have you tried to follow this quickstart? Please, try to follow it thoughtfully and explain if you get any error finishing the quickstart.

    Anyway, before running your Java script, try running on the console the following (please modify with the exact path where you store your key):

    export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/mp6key.json"
    

    How are you authenticating your credentials in your Java script?