This is my SchedulingStarter
@SpringBootApplication
@EnableScheduling
@Import({SchedulingConfig.class})
@EnableConfigurationProperties({ScheduleQueryProperties.class, ScheduleThreadPoolProperties.class,
ScheduleUnblockMaintenceLimitQueryProperties.class, ScheduleUnblockMaintenceLimitThreadPool.class})
public class SchedulingStarter {
private static final Logger LOGGER = LoggerFactory.getLogger(SchedulingStarter.class);
public static void main(String[] args) {
Security.addProvider(new BouncyCastleProvider());
try {
SSLUtil.turnOffSslChecking();
} catch (NoSuchAlgorithmException | KeyManagementException e) {
LOGGER.error(e.getMessage(), e);
}
SpringApplication.run(SchedulingStarter.class, args);
}
}
and this is the class that contains the method annotated with @Scheduled(cron = "${schedule.account.unblock.process-time}")
@Slf4j
@Component
public class LimitMaintenceFlowSchedule {
@Autowired
private LimitMaintenceFlowScheduleService limitMaintenceFlowScheduleService;
@LogProfiler
@LogInfo(logResult = true)
@Scheduled(cron = "${schedule.account.unblock.process-time}")
@Trace(dispatcher = true)
public void executeToProcess() {
log.info("m=execute, msg=Iniciando job de consulta ao manager para mudança de status");
this.limitMaintenceFlowScheduleService.processLimitMaintenceFlow();
}
}
I'm using this bootstrap.yml file for my tests
schedule:
account:
overlimit:
process-time: "0 0 4 ? * *"
process-error-time: "0 0 4 ? * *"
unblock:
process-time: "0 0 4 ? * *"
process-error-time: "0 0 4 ? * *"
thread-pool:
name-prefix: schedule-job-executor
core-pool-size: 1
max-pool-size: 2
queue-capacity: 1
use-max-available-processors: false
query:
limit-size: 100
execution-count: 3
execute-until-end: true
stacktrace
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'limitMaintenceFlowSchedule' defined in file [/home/emanzini/IdeaProjects/cards/credit-card-utils/scheduling/build/classes/java/main/ps/card/utils/scheduling/schedule/LimitMaintenceFlowSchedule.class]: Initialization of bean failed; nested exception is java.lang.IllegalStateException: Encountered invalid @Scheduled method 'executeToProcess': Could not resolve placeholder 'schedule.account.unblock.process-time' in value "${schedule.account.unblock.process-time}"
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:601) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:849) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) ~[spring-boot-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at ps.card.utils.scheduling.SchedulingStarter.main(SchedulingStarter.java:39) ~[main/:na]
Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'executeToProcess': Could not resolve placeholder 'schedule.account.unblock.process-time' in value "${schedule.account.unblock.process-time}"
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.processScheduled(ScheduledAnnotationBeanPostProcessor.java:496) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$null$1(ScheduledAnnotationBeanPostProcessor.java:359) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na]
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.lambda$postProcessAfterInitialization$2(ScheduledAnnotationBeanPostProcessor.java:359) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at java.base/java.util.LinkedHashMap.forEach(LinkedHashMap.java:684) ~[na:na]
at org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor.postProcessAfterInitialization(ScheduledAnnotationBeanPostProcessor.java:358) ~[spring-context-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:429) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1766) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.5.RELEASE.jar:5.1.5.RELEASE]
... 15 common frames omitted
CodePudding user response:
You must put the configuration in a file called application.yml