JAVA与groovy脚本的结合使用
今天要给大家说一个好东西,自由分配配置,那就是我们可以在项目中,执行groovy脚本
下面直接开始流程:
1.pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-groovy-templates</artifactId>
</dependency>
2.在application.yml
写入我们执行脚本的内容
allotProvider: if(!org.springframework.util.StringUtils.isEmpty(taskInfo.provider)) {return taskInfo.provider;};int a = new Random().nextInt(10);if(a > 5) {return 'youyu';};return 'juxinli';
3.在Java项目中获取这个配置信息

4.开始封装groovy脚本执行

至此我们就把Groovy和Java结合起来使用了。

浙公网安备 33010602011771号