Spicy Spring: Java System Properties As Configuration Properties With Spring Boot

In a previous post we learned that configuration property values can be passed via environment variables. With Spring Boot we can also pass the values using Java system properties. So if we have a property sample.message then we can use -Dsample.message=value to pass a value when we run the application. If we use the Spring Boot Gradle plugin we must reconfigure the bootRun task to pass Java system properties from the command-line.

Let’s reuse our sample application from the previous blog post:

Our Gradle build file now looks like this:

Now we can run the following command from the command-line and set a value for the sample.message configuration property:

Written with Spring Boot 1.2.5.RELEASE and Gradle 2.7.

Original article

This entry was posted in Spring and tagged , , by mrhaki. Bookmark the permalink.

About mrhaki

My name is Hubert A. Klein Ikkink also known as mrhaki. I work at the great IT company JDriven. Here I work on projects with Groovy & Grails, Gradle and Spring. At JDriven we focus on SpringSource technologies. All colleagues want to learn new technologies, support craftmanship and are very eager to learn. This is truly a great environment to work in. You can contact me via Google+ or @mrhaki.

3 thoughts on “Spicy Spring: Java System Properties As Configuration Properties With Spring Boot

    • Hi Stephane, thank you for you comment. And you’re absolutely right with your suggestion. I find that with Spring Boot there a lot of different ways to achieve something.

      • I guess its not the Spring Boot way to use @Value. And of all the interesting Spring Boot (Spring Cloud Config) topics, this is the least interesting IMHO :P

Leave a Reply

Your email address will not be published. Required fields are marked *