I have an application.properties
file that looks like this:
mcl.sso.frontend-url=http://blah.com:9001
mcl.sso.mocking-agent=false
I am trying to override these two variables from the command line. This should be possible by setting environment variables. Here's how I'm running the command:
MCL_SSO_FRONTEND_URL='foobar' MCL_SSO_MOCKING_AGENT='true' ./gradlew run
However, when I print out the values of these variables, mcl.sso.mocking-agent
equals "true" (as expected), but mcl.sso.frontend-url
still equals "http://blah.com:9001" (unexpected). Why doesn't mcl.sso.frontend-url
change the value of the property? I can only assume this has something to do with the way Spring converts environment variables into property keys, but I can't find any specific documentation on this.
Environment-Specific Properties File. If we need to target different environments, there's a built-in mechanism for that in Boot. We can simply define an application-environment. properties file in the src/main/resources directory, and then set a Spring profile with the same environment name.
Another way to read application properties in the Spring Boot application is to use the @ConfigurationProperties annotation. To do that, we will need to create a Plain Old Java Object where each class field matches the name of the key in a property file.
properties in default location. Spring Boot loads the application. properties file automatically from the project classpath. All you have to do is to create a new file under the src/main/resources directory.
This has been fixed as of Spring Boot 1.2.5
. Previously, you'd have to use MCL_SSO_FRONTEND-URL
(notice the dash that can't be translated to an underscore).
You can play with bindings using this sample project.
Just get rid of the dash:
mcl.sso.mocking-agent > MCL_SSO_MOCKINGAGENT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With