1.propertie configuration data read
/ ** * value by taking the data in the configuration file * / @Component @PropertySource (value = { "config / db-config.properties" }) public class InfoConfig1 { @Value ( "{$ } db.username " ) Private String useranme; @Value ( " db.Password $ {} " ) Private String password; public String getUseranme () { return useranme; } public void setUseranme (String useranme) { the this .useranme = useranme; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String toString() { return ""; } }
2.取值
@RestController public class InConfigController { @Autowired private Environment env; @Value("${db.username}") private String username; @RequestMapping(value = "/info") public String getValue() { String username = env.getProperty("db.username"); String password = env.getProperty("db.password"); return username; } @RequestMapping(value = "/info2") public void getValue1() { System.out.println(username); } }