2.获取配置文件中的值
比如配置文件中有如下自定义配置:
author.name=revin
author.age=28方式1:
@Value方式
public class Test {
@Value("${author.name}")
private String name;
@Value("${author.age}")
private Long age;
///...省略 set get方法
}方式2:
@ConfigurationProperties
@ConfigurationProperties(prefix="author")
public class AuthorSettings {
private String name;
private Long age;
///...set get 省略
}通过@ConfigurationPropertie加载文件内的配置,可以使用第二个参数locations指定配置文件locations={classpath:xxxxxx}
Last updated
Was this helpful?