Values not populated from application.properties files
Closed this issue · 5 comments
Note that all other settings are working just fine.
I only recently adderd Spring Cloud GCP - it's the only piece that does not work as expected currently.
I am running a particular profile which points locally to a credentials file as follows:
spring.cloud.gcp.project-id=<project-id>
spring.cloud.gcp.credentials.location=file:/path/to/file/credentials.json
If I run the same thing with GOOGLE_APPLICATION_CREDENTIALS=/path/to/file/credentials.json
it's working.
What am I missing?
Caused by: 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.
at com.google.auth.oauth2.DefaultCredentialsProvider.getDefaultCredentials(DefaultCredentialsProvider.java:134) ~[google-auth-library-oauth2-http-0.22.0.jar:na]
at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:119) ~[google-auth-library-oauth2-http-0.22.0.jar:na]
at com.google.auth.oauth2.GoogleCredentials.getApplicationDefault(GoogleCredentials.java:91) ~[google-auth-library-oauth2-http-0.22.0.jar:na]
at com.google.api.gax.core.GoogleCredentialsProvider.getCredentials(GoogleCredentialsProvider.java:67) ~[gax-1.60.0.jar:1.60.0]
at org.springframework.cloud.gcp.core.DefaultCredentialsProvider.getCredentials(DefaultCredentialsProvider.java:67) ~[spring-cloud-gcp-core-1.2.6.RELEASE.jar:1.2.6.RELEASE]
I am using spring-cloud-gcp-starter
(gradle):
// Spring Cloud Google Secret Manager
implementation 'org.springframework.cloud:spring-cloud-gcp-starter:1.2.6.RELEASE'
implementation 'org.springframework.cloud:spring-cloud-gcp-starter-secretmanager:1.2.6.RELEASE'
Update
It appears to be the same for other properties e.g. database name:
spring.cloud.gcp.sql.database-name=<db-name>
Debugging the code confirms that the properties are not getting set:
It looks like you're using the secretmanager module -- those settings have to be put in a bootstrap.properties instead of application.properties.
This is because the secrets are loaded by the "bootstrap phase" of Spring. The bootstrap.properties
file is placed in the resources/
directory same as the application.properties
file.
Let me know if this fixes the problem for you. I will also look into ways of documenting this better -- were you looking at sample apps or docs, etc.?
EDIT: Not sure why the database name is not being picked up though. Those settings should be correctly read by application.properties
. We would probably need to see more dependencies being used in the project to understand.
Hi @falk-stefan perhaps you can share the full credentials file and maybe the bootstrap file (if there), so we can get a full picture.
Please do not share the full credentials file. That's supposed to stay a secret ;-)
Oh..my bad!...I should have said, the applications.properties
file and the bootstrap
file ;-)
Sorry for the late response. I was somehow able to make this work but I cannot tell what the problem really was. But it was definitely something on my side so I guess we can close this issue. Thank you!