有条件的Spring Boot @EnableScheduling

有条件的Spring Boot @EnableScheduling,第1张

条件的Spring Boot @EnableScheduling

我解决了这个问题,这是我以后做的参考:

  • 从我的应用中删除了@EnableScheduling批注
  • 添加了新的配置类和条件,以基于应用程序属性启用/禁用调度

--

 @Configuration public class Scheduler {    @Conditional(SchedulerCondition.class)    @Bean(name = TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME)    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)    public ScheduledAnnotationBeanPostProcessor scheduledAnnotationProcessor() {        return new ScheduledAnnotationBeanPostProcessor();    }}

和条件班

public class SchedulerCondition implements Condition {    @Override    public boolean matches(ConditionContext context, AnnotatedTypemetadata metadata) {        return Boolean.valueOf(context.getEnvironment().getProperty("com.myapp.config.scheduler.enabled"));    }}

另外,要在后端服务器上禁用Web服务器,只需将以下内容添加到application.properties文件中:

spring.main.web_environment=false


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5046059.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-15
下一篇2022-11-15

发表评论

登录后才能评论

评论列表(0条)

    保存