一、在resources下面创建test.properties文件
com.test.name=z
com.test.age=0
二、创建User
@Configuration
@PropertySource(value = "classpath:test.properties") //找到配置文件
@ConfigurationProperties(prefix = "com.test")//对应的类
public class User {
}
三、创建ResourceController
@Autowired
private User user;
@RequestMapping(value = "/getTestProperties")
public String getTestProperties(){
return user.toString();
}
自动打印配置内容