@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; } //Notice! Configure a Bean of PropertySourcesPlaceholderConfigurer // @Bean // public static PropertySourcesPlaceholderConfigurer propertyConfigure() { // return new PropertySourcesPlaceholderConfigurer(); // } }
Reference: http://blog.csdn.net/flygoa/article/details/58075398