How to set server.address from os env vars to java spring boot properties?

Have a simple Spring Boot project and specific properties file with this content:

server:
  address: ${SERVER_HOST}
  port: ${SERVER_PORT}

The env vars are set from OS from the service, but server.address in Spring Boot is java.net.InetAddress:

Failed to bind properties under 'server.address' to java.net.InetAddress:

    Property: server.address
    Value: "${SERVER_HOST}"
    Origin: class path resource [config/application.yaml] - 20:12
    Reason: failed to convert java.lang.String to java.net.InetAddress (caused by java.net.UnknownHostException: ${SERVER_HOST})

My environment is:

SERVER_HOST=127.0.0.1
SERVER_PORT=8080

How to transform the String value to InetAddress in property file? or where is the correct way to set this value?

Guess that your environment variable is not configured property and so it is actually parsing ${SERVER_HOST} rather than 127.0.0.1. You can use the command printenv (in case of linux and macOS) to verify what are the actual value of the environment variables to see if they are really configured or not.

Leave a Comment