You can use Spring Environment
abstraction for that.
First you need to add Property Source to your Java Configuration file
@Configuration
@PropertySource("classpath:/com/mypacakge/core-message.properties")
public class AppConfig {
Or if you have multiple properties files
@Configuration
@PropertySources({
@PropertySource("classpath:core-message.properties"),
@PropertySource("classpath:database.properties")
})
public class AppConfig {
Add PropertySourceConfigurer
to to your Java Configuration file
@Bean
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
return new PropertySourcesPlaceholderConfigurer();
}
Now let's say that in your core-message.properties
you have the following data
message.name=Hello
You can retrieve this data in any bean by autowiring Environment
abstraction and then calling env.getProperty()
@Autowired
Environment env;
public void m1(){
String message = env.getProperty("message.name")` // will return Hello
Environment
object provides interface to configure property sources and resolve properties. It provides convenience to read from a variety of sources: properties files, system environment variable, JVM system properties, servlet context parameters, and so on, which is very useful. For example :
environment.getSystemProperties().put("message", "Hello");
System.getProperties().put("message", "Hello");
environment.getSystemProperties().get("message"); // retrieve property
environment.getPropertySources() // allows manipulation of Properties objects
Spring Reference Documentation - Environment