1
votes

I'm having some trouble trying to pass JVM arguments to a Spring Boot application from build.gradle file.

My build.gradle looks like this:

buildscript ...

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'

...
def devConfigFolder = "/abc"
applicationDefaultJvmArgs = ["-DconfigFolder=$devConfigFolder"]
dependencies {
   ...
}

And the class where I try to use the placeholder:

@Component
public class PClass {

   private static final String CONF = "configFolder";
   @Value("${" + CONF+ "}")
   private String configFolder;
}

And this is the exception I'm receiving:

IllegalArgumentException: Could not resolve placeholder 'configFolder' in value "${configFolder}"

I've tried with bootRun{jvmArgs}, but it doesn't work.

1

1 Answers

0
votes

You can set these values in application.property /yml file and use that property key in @value annotation.

application-prod.properties

configFolder="somefolder/path"

These property files can be set/modified in runtime.

You can take a look at this (5.1) section: https://www.baeldung.com/properties-with-spring Is that fine for you?? If not please let me know.