0

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?

New contributor
paulfilip is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • those are 2 different variables: 1.CUSTOMCONNSTR_DBCONN_IP and 2. CUSTOMCONNSTR_TEST_ENV_VARIABLE
    – J Asgarov
    Commented 35 secs ago

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.