I have a Java Spring Boot app deployed on Microsoft Azure that is connected to a PostgreSQL database. I want to connect to the database using credentials stored in Azure as Connection strings. The problem is that when the app is starting, it fails because the environment variable is not valid.
In Azure, I configured a connection string called DBCONN_IP with "Custom" type. As the documentation says, this will be available as environment variable called CUSTOMCONNSTR_DBCONN_IP in app.
In application.properties I have the following:
database.ip = ${CUSTOMCONNSTR_DBCONN_IP:localhost}
When application starts, the connection is refused, because the environment variable is not valid and it replaces it with localhost, therefore the application is not started at all.
However, I added a simple controller that just returns the value of another environment variable set as a connection string:
@GetMapping
public ResponseEntity<String> test() {
try {
String envString = System.getenv("CUSTOMCONNSTR_TEST_ENV_VARIABLE");
return new ResponseEntity<>(envString, HttpStatus.OK);
} catch (Exception e) {
return new ResponseEntity<>(e.getMessage(), HttpStatus.FORBIDDEN);
}
}
This works and the correct value is returned. My question is why the connection string accessed in application.properties is invalid? Should I set something else in Azure or am I missing something?
CUSTOMCONNSTR_DBCONN_IP
and 2.CUSTOMCONNSTR_TEST_ENV_VARIABLE