I have a spring @configuration annotated class MappingsClientConfig with a boolean field as:
@Value(\"${mappings.enabled:true}\")
private boolean mappi
This is how it was solved in our project, as the other answers didn't work for us. We were using spring batch, also.
main job config:
@Configuration
@EnableBatchProcessing
@PropertySource("classpath:application.properties")
public class MainJobConfiguration {
@Autowired
PipelineConfig config;
@Bean
public PipelineConfig pipelineConfig(){
return new PipelineConfig();
}
// To resolve ${} in @Value
@Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigInDev() {
return new PropertySourcesPlaceholderConfigurer();
}
// job stuff ...
}
properties config loader:
public class PipelineConfig {
@Value("${option}")
private boolean option;
}
Note how the @Value
is in the PipelineConfig, but the actual properties from which the option is loaded, is specified in the job class.