@Component
@PropertySource("classpath:url.properties")
@ConfigurationProperties(prefix = "vhall")
public class VhallUrl {
private String userName;
private String password;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
//注意!配置一个PropertySourcesPlaceholderConfigurer的Bean
// @Bean
// public static PropertySourcesPlaceholderConfigurer propertyConfigure() {
// return new PropertySourcesPlaceholderConfigurer();
// }
}
参考:http://blog.youkuaiyun.com/flygoa/article/details/58075398
本文介绍如何使用Spring Boot通过@Component, @PropertySource及@ConfigurationProperties注解来配置属性源并实现属性映射到Java Bean的过程。具体展示了VhallUrl类如何加载url.properties文件中的配置信息。
1281

被折叠的 条评论
为什么被折叠?



