Search code examples
spring-bootvariablessystemapplication.properties

how to set application property variable with system eviroment


I need to set applcation properties variable with system variable Ex.

my system variable enviroment on widows is USER_NAME = admin

I want that set spring.datasource.username with USER_NAME

I tryed to do this mode:

in application.properties file spring.datasource.username={USER_NAME}

but dind't set.

anybody knows how to do?


Solution

  • In your application properties the values should be with lower case and separated by point:

    spring.datasource.username=${user.name}
    

    Your environment variable should be as you've mentioned:

    USER_NAME=admin