Groovy中的Spring Boot外部配置

ACV*_*ACV 4 groovy spring-boot

如何让Spring启动加载Groovy的外部属性?需要类似于java机制的东西(资源中的application.properties和带有@Value注释的ConfigBean)?

当尝试使用与java相同的机制时,我不知道如何注释ConfigBean

@Component
public class ConfigBean {
    @Value("${seleniumAddress}")
    private String seleniumAddress; ...
Run Code Online (Sandbox Code Playgroud)

然后在 application.properties

seleniumAddress=http://localhost:4444/wd/hub
Run Code Online (Sandbox Code Playgroud)

但是对于groovy,我无法使用@Value("${seleniumAddress}" 它来注释该字段,它会引发错误抱怨"$ {}" - 这是groovy中的特殊序列.那么我应该在这里使用什么机制呢?

谢谢

Dav*_*yer 12

如果在Groovy中对Spring占位符使用"$ {}",则必须确保它是一个String(而不是GString):即使用'$ {}'(单引号).