With Spring in xml context we can simple load properties like this:
<context:property-placeholder location:"classpath*:app.properties"/>
You can use the annotation @PropertySource
like this
@Configuration
@PropertySource(value="classpath*:app.properties")
public class AppConfig {
@Autowired
Environment env;
@Bean
public TestBean testBean() {
TestBean testBean = new TestBean();
testBean.setName(env.getProperty("testbean.name"));
return testBean;
}
}
EDIT: if you are using spring boot you can use @ConfigurationProperties
annotation to wire the properties file directly to bean properties, see:
https://www.mkyong.com/spring-boot/spring-boot-configurationproperties-example/