springboot以其开箱即用,入门门槛低的特性越来越受开发者欢迎,使用过spring的人都知道spring的入门首先要解决的就是繁杂的配置,而springboot在这方面就做的很到位--快速上手!
笔者今天在使用中就遇到一个很奇怪的问题:注释掉spring-boot-starter-actuator依赖后,原本正常工作的任务不工作了,其实这个问题就在于没好好看springboot关于task使用时的警告:
上面的意思就是要使用任务的话你做好乖乖的使用@EnableScheduling注解,否则有你好看
@EnableScheduling
ensures that a background task executor is created. Without it, nothing gets scheduled.
好了不卖关子了,我们来看一下spring-boot-starter-actuator依赖与任务有什么猫腻:
@Configuration
@EnableScheduling
@ConditionalOnProperty(value = "spring.metrics.export.enabled", matchIfMissing = true)
@EnableConfigurationProperties
public class MetricExportAutoConfiguration
spring-boot-starter-actuator这个依赖存在时会自动帮你加上EnableScheduling注解,到这里就解释了为什么我们不在configuration里面加EnableScheduling注解去掉spring-boot-starter-actuator依赖后任务就不工作的问题!
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有