[亲测]springboot中如何手动运行定时任务(方法中包含调用其他接口)

[亲测]springboot中如何手动运行定时任务(方法中包含调用其他接口)springboot 中定时执行 signForJob 方法 当启动项目加载完配置后执行 afterPropert 方法 代码如下 package cn com casmart scheduling job orders import cn com casmart common domain common

大家好,我是讯享网,很高兴认识大家。

springboot中定时执行signForJob()方法,当启动项目加载完配置后执行afterPropertiesSet()方法
在这里插入图片描述
讯享网

代码如下:

package cn.com.casmart.scheduling.job.orders; import cn.com.casmart.common.domain.common.JResult; import cn.com.casmart.common.domain.entity.member.Institutes; import cn.com.casmart.scheduling.api.InstitutesApi; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.util.List; import org.springframework.beans.factory.InitializingBean; @Component public class OrdersDeliveryJob implements InitializingBean { 
    private static final Logger logger = LoggerFactory.getLogger(OrdersDeliveryJob.class); @Autowired InstitutesApi institutesApi; @Scheduled(cron = "0 10 2 * * ? ") public void signForJob() { 
    try { 
    JResult<List<Institutes>> jResult = institutesApi.getSelfInspection(); List<Institutes> institutesList = jResult.getData(); } catch (Exception e) { 
    logger.error("*任务处理时出错", e); } } @Override public void afterPropertiesSet() throws Exception { 
    signForJob(); } } 

讯享网
小讯
上一篇 2025-03-19 23:16
下一篇 2025-01-19 16:41

相关推荐

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/134742.html