整合步骤
- 使用properties文件测试数据
- 在java类添加
@PropertySource("classpath:/properties/person.properties")//单个文件属性配置
@PropertySources({@PropertySource("classpath:/properties/person.properties")})//多个文件进行属性配置
properties文件内容
person.id=1000
person.name=tomcat
类中实现
@RestController
//@PropertySource("classpath:/properties/person.properties")//单个属性文件赋值
//多个属性文件赋值可用集合形式
@PropertySources({@PropertySource("classpath:/properties/person.properties")})//可以多个文件同时赋值
public class PersonController {
@Value("${person.id}")
private Integer personId;
@Value("${person.name}")
private String personName;
@RequestMapping("/getMsg3")
public String getMsg(){
return personId + ": " + personName;
}
}
结果验证