Spring Boot: Set defaultValue in RequestParam to a value in application.properties?

Viewed 337

Is there a way to set the defaultValue to a value from the application.properties file?

@ResponseBody
public void test(@RequestParam(name="testValue", defaultValue = <something from application.properties>))
1 Answers

Declare your defaultValue as a controller variable like this

@Value("${variable.name.in.app.properties}")
private String myDefaultValue;

Then, in your controller action, assign it like this

@ResponseBody
public void test(@RequestParam(name="testValue", defaultValue = myDefaultValue))
Related