config.name=configname
config.password=configpassword
@Configuration @ConfigurationProperties(prefix = "config") @PropertySource("classpath:/config.properties") public class Config { private String name; private String password; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } }
@EnableConfigurationProperties({Config.class})
使用的时候直接注入即可
@Autowired
Config config;
@ComponentScans({@ComponentScan("com.dx.controller"), @ComponentScan("app.config")})