第一步:在yml中添加属性值
#yml自定义属性basic: name:robin password:123456 address:上海市黄浦区
第二步:创建装配工具类
@Data@Configuration//定义配置类public class ConfUtils {@Value("${basic.name}") private String name;@Value("${basic.password}") private String password;@Value("${basic.address}") private String address;}
第三步:Groovy脚本获取Bean,读取yml属性值
友情链接 : Groovy获取Bean两种方式 你过来呀!
@Slf4jclassLoadBeanimplementsRunnable{privateString name;privateString password;privateString address;/**
* .
* Groovy获取Bean
*/@Overridevoid run() { log.info("Groovy开始执行,当前类{}",this.getClass()) ConfUtils conf = TestgroovyApplication.applicationContext.getBean(ConfUtils.class)this.name = conf.getName()this.password = conf.passwordthis.address = conf.getAddress() log.info("姓名:[{}],密码:[{}],地址:[{}]", name, password, address) log.info("Groovy结束执行,当前类{}",this.getClass()) }}
网友评论