Storing property in more than one place can be confusing for other programmers.
And the keys should be unique to preserve consistency
I recommend to decide from which property file you want to read the value.
1. Reading from application.properties
See example here:
How to access a value defined in the application.properties file in Spring Boot
Access it from any @Component
as @Eugen Covaci suggested with @Value
:
@Value("${org.quartz.jobStore.host}")
private String name;
2. Reading from quartz.properties
This way you are open for new properties (I assume you will have more if you created a separate property file).
See my example below:
QuartzProperties POJO (each field is a property)
public class QuartzProperties {
private String jobHost;
public String getJobHost() { return jobHost; }
public void setJobHost(String jobHost) { this.jobHost = jobHost; }
}
Configuration class
@Configuration
@PropertySource("classpath:quartz.properties")
public class QuartzConfig {
@Value("${org.quartz.jobStore.host}")
String jobHost;
//other properties for Quartz here
@Bean
public QuartzProperties quartzProperties(){
QuartzProperties quartzProperties = new QuartzProperties();
quartzProperties.setJobHost(jobHost);
//setters for other properties here
return quartzProperties;
}
@Bean
public static PropertySourcesPlaceholderConfigurer properties(){
return new PropertySourcesPlaceholderConfigurer();
}
}
Access it from any @Component
by quartzProperties.getJobHost()
.
I just named it as quartzProperties and QuartzConfig but it can be jobStoreProperties or JobStoreConfig. Depends on the purpose of these properties.
Or if you want to create 2 profiles (dev & test for example) you could create them following the Spring YAML Configuration
Or you can externalize the configuration as an environment variable/pass it as a command line argument.
Externalized Configuration