I want to set a system property when running a spring boot application in IntelliJ, and then get it in my program. I am using IntelliJ Idea CE.
Initially I tried in a normal Java project (not spring or maven). I just set the value in "VM Options" in run configurations (Ex: -DpropertyName=propertyValue). And then I ran the main function, I was able to access it by System.getProperty("propertyName")
.
Now I want to do the same with my spring boot project. Its packaging is war. As I am using Community Edition, I run the project by running the maven command spring-boot:run. How do I pass a system property here?
I have tried adding the property in "VM Options" in the run configuration.
I have tried below commands -
spring-boot:run -DpropertyName=propertyValue
spring-boot:run --propertyName=propertyValue
spring-boot:run -Drun.jvmArguments="-DpropertyName=propertyValue"
But in all approaches, when I am getting the property value in my method, it gives null.
Any suggestions are welcome.
EDIT Adding code snipped as requested
public static boolean isSomething() {
return !StringUtils.equals(System.getProperty("propertyName"), Constants.CONSTANT_VALUE);
}