In my application I have method annotated with @Scheduled(cron="${my.cron.prop}")
I don't have my.cron.prop
in property file and my job just don't start but application starts successfully.
But when I add dependecy:
compile ("de.codecentric:spring-boot-admin-starter-client:1.5.7")
My application fails to start:
Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'reportCurrentTime': Could not resolve placeholder 'my.cron.prop' in value "${my.cron.prop}"
How can I fix it?
Expected behaviour - just don't start job in case of property is not provided
I guess you application did not @EnableScheduling
, spring-boot-admin-starter-client does.
You could avoid this by providing a default value: see other answer
a nicer way to fix this is to use a dedicated component to launch your job when the property is available
@Component
@ConditionalOnProperty( name = "my.cron.prop" )
public class Tasks {
@Scheduled(cron = "${my.cron.prop}")
public void task() {
/*do your suff*/
}