yml文件-动态开关

本质:${} 读取字符串

方案一

增加一个属性swith来判断业务流走向

//test.swith是配置文件中定义的参数
@value("${test.swith}") 
String swith;

public  void func() {
    if("on".equals(swith)){
    //执行对应的定时任务代码
    }
}

 

方案二

通过@ConditionalOnProperty注解来决定是否注入spring容器

@Component
@EnableScheduling
@ConditionalOnProperty(name = "timer.enabled")
public class ConditionalOnPropertyTest {

    @Scheduled(cron = "*/5 * * * * ?")
    public void test(){
        logger.info("定时器执行....");
    }
}

 

 

参考文章

【1】@ConditionalOnProperty注解用法

posted @   先娶国王后取经  阅读(17)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· AI与.NET技术实操系列(六):基于图像分类模型对图像进行分类
历史上的今天:
2023-03-22 Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Circular view path [jxsr2]:
2022-03-22 MySQL经典50题
点击右上角即可分享
微信分享提示