大佬教程收集整理的这篇文章主要介绍了有条件的Spring Boot @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
有没有一种方法可以根据应用程序属性使@Enablescheduling有条件?也可以基于属性禁用控制器吗?
我要实现的目标是拥有用于服务Web请求的相同的Spring
Boot应用程序(但不能在同一台计算机上运行计划的任务),并且还要在后端服务器上安装同一应用程序以仅运行计划的任务。
我的应用看起来像这样
@SpringBootApplication
@Enablescheduling
@EnabletransactionManagement
public class MyApp {
public static void main(String[] args) {
SpringApplication.run(MyApp.class,args);
}
}
预定的工作样本如下所示
@Component
public class myTask {
@scheduled(fixedRate = 60000)
public void doSomeBACkendJob() {
/* job implementation here */
}
}
以上是大佬教程为你收集整理的有条件的Spring Boot @EnableScheduling全部内容,希望文章能够帮你解决有条件的Spring Boot @EnableScheduling所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。