Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot external configuration in Groovy

How to get Spring boot to load external properties for Groovy? Need something similar to java mechanism (application.properties in resources and ConfigBean with @Value annotations)?

When trying to use the same mechanism as with java, I don't know how to annotate the ConfigBean

@Component
public class ConfigBean {
    @Value("${seleniumAddress}")
    private String seleniumAddress; ...

and then in application.properties

seleniumAddress=http://localhost:4444/wd/hub

but with groovy I cannot annotate the field with @Value("${seleniumAddress}" It throws an error complaining about "${}" - this is a special sequence in groovy. So what mechanism should I use here?

Thank you

like image 722
ACV Avatar asked Dec 08 '22 05:12

ACV


1 Answers

If you use "${}" for Spring placeholders in Groovy you have to make sure it's a String (not a GString): i.e. use '${}' (single quotes).

like image 164
Dave Syer Avatar answered Dec 11 '22 10:12

Dave Syer