I am working in a legacy software where most of the configuration is externalized from application.properties it resides in a file called custom.properties which will be read into a configuration bean that is declared like that.
@Configuration
@ConfigurationProperties(locations = "classpath:custom.properties", ignoreUnknownFields = true, prefix = "custom")
public class CustomProperties {
...
}
This application has some scheduled tasks, which where declared to work at a fixed interval and time. @Scheduled(cron = "0 0 16 * * 3") Until now everything works fine. Recently I have been asked to make this cronjob happen at a configurable time. So I added another property to custom.properties and an attribute to CustomProperties (including getter and setter). Next I altered the scheduled annotation to look like this. @Scheduled(cron = "${@customProperties.cronJob1Schedule}")
When I start the application I get the following exception:
java.lang.IllegalStateException: Encountered invalid @Scheduled method 'cronJob1': Could not resolve placeholder '@customProperties.cronJob1Schedule' in string value "${@bwvProperties.cronJob1Schedule}"
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.processScheduled(ScheduledAnnotationBeanPostProcessor.java:406)
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:282)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:422)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
Has anybody had that issue before? Why cant I access the configuration bean in SpEL?