读取配置文件

你。 提交于 2020-02-26 05:39:21

1.配置文件

获取配置文件类

@Data
@Component
@ConfigurationProperties(prefix = "test.setting")
public class CommonConfig {
    private String str;
    private List<Integer> list;
    private List<ConfigEntity> configEntityList;
}

 application.properties文件

test.setting.str = "this is a String Type in CommonConfig"
test.setting.list[0] = 1
test.setting.list[1] = 2
test.setting.list[2] = 3
test.setting.configEntityList[0].id = "testConfigEntityId-0"
test.setting.configEntityList[0].content = "testConfigEntityContent-0"
test.setting.configEntityList[1].id = "testConfigEntityId-1"
test.setting.configEntityList[1].content = "testConfigEntityContent-1"

 在使用类中自动装配

@Autowired
private CommonConfig commonConfig;

 2.定时任务

@Scheduled(cron = "${taskTime.redis}")

配置文件

taskTime.redis=0 0/1 * * * ?
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!