Wondercease

浙ICP备2022017321号

新增配置文件

一、在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();
}

自动打印配置内容

发表评论

您的电子邮箱地址不会被公开。