开发一数据接收WebService,里面用到定时任务@Scheduled
每次会重复运行三次
@Slf4j @PropertySource("classpath:common-config.properties") @Component public class ScheduledController { @Scheduled(cron="${jobs.schedule.report}") public void dataReportScheduled() { try{ log.info("...end report data scheduled!\r\n\"); }catch (Exception e){ log.error("定时任务出现异常:"+e.getMessage()); } } }
最后查出来问题在下面的配置文件中红色字体部分,注释掉问题即可解决
package com.xxxxxxx.config; import com.xxxxxxx.interceptor.AuthInterceptor; import com.xxxxxxx.service.biz.IDataCenterBaseService; import com.xxxxxxx.service.biz.impl.DataCenterBaseService; import com.xxxxxxx.service.biz.impl.TransferDataServiceImpl; import com.xxxxxxx.webservice.TransferDataService; import org.apache.cxf.Bus; import org.apache.cxf.bus.spring.SpringBus; import org.apache.cxf.jaxws.EndpointImpl; import org.apache.cxf.transport.servlet.CXFServlet; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; import org.springframework.web.servlet.DispatcherServlet; import javax.xml.ws.Endpoint; @Configuration public class CXFConfig { /******************************************************* * WebService配置 * @return *******************************************************/ @Bean public IDataCenterBaseService dataCenterService() { return new DataCenterBaseService(); } @Bean public AuthInterceptor authInterceptor() { return new AuthInterceptor(dataCenterService()); } @Bean public ServletRegistrationBean dispatcherServlet() { return new ServletRegistrationBean(new CXFServlet(), "/service/*"); } @Bean(name = Bus.DEFAULT_BUS_ID) public SpringBus springBus() { return new SpringBus(); } @Bean public TransferDataService transferDataService() { return new TransferDataServiceImpl(); } @Bean public Endpoint endpoint() { EndpointImpl endpoint = new EndpointImpl(springBus(), transferDataService()); endpoint.publish("/transfer"); endpoint.getInInterceptors().add(authInterceptor()); return endpoint; } /******************************************************* * Web应用配置 * @return *******************************************************/ @Bean public ServletRegistrationBean restServlet(){ //注解扫描上下文 AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext(); //base package applicationContext.scan("com.xxxxxxx"); //通过构造函数指定dispatcherServlet的上下文 DispatcherServlet rest_dispatcherServlet = new DispatcherServlet(applicationContext); //用ServletRegistrationBean包装servlet ServletRegistrationBean registrationBean = new ServletRegistrationBean(rest_dispatcherServlet); registrationBean.setLoadOnStartup(1); return registrationBean; } @Bean public ServletRegistrationBean cooleadServlet(){ //注解扫描上下文 AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext(); //base package applicationContext.scan("com.xxxxxxx"); //通过构造函数指定dispatcherServlet的上下文 DispatcherServlet rest_dispatcherServlet = new DispatcherServlet(applicationContext); //用ServletRegistrationBean包装servlet ServletRegistrationBean registrationBean = new ServletRegistrationBean(rest_dispatcherServlet); registrationBean.setLoadOnStartup(1); //指定urlmapping registrationBean.addUrlMappings("/xxxxxxx/*"); //指定name,如果不指定默认为dispatcherServlet registrationBean.setName("xxxxxxx"); return registrationBean; } }
去网上搜了一下相关的帖子,有类似问题的
https://blog.csdn.net/tly_74125/article/details/80925599
相关推荐
SpringBoot实现定时任务的动态开启关闭,如有疑问联系wx: hsj179540
基于springboot的定时任务实现
SpringBoot定时任务实现Oracle和mysql数据同步
springboot 定时任务(线程配置,并行【同步】、异步等)
1. SpringBoot 自定义线程池以及多线程间的异步调用(@Async、@EnableAsync) 2.Java多线程之定时任务 以及 SpringBoot多线程实现定时任务 3.@EnableScheduling 与 @Scheduled
玩转SpringBoot之定时任务详解,
springboot动态配置定时任务(schedule),可不重启项目实现开关重启任务,改变任务定时规则
本篇文章主要介绍了SpringBoot 创建定时任务(配合数据库动态执行),小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Springboot中使用数据库配置定时任务,并在Job中自动装配Spring容器Bean。
主要介绍了springboot schedule 解决定时任务不执行的问题,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下
Spring定时任务的几种实现,欢迎交流!
在springboot中通过读取数据库的定时任务信息,动态生成quartz定时任务
SpringBoot2 与 Quartz 整合的Demo。 后台可添加、修改、移除 定时任务。 也可查看当前任务的状态 灵活的定时任务
SpringBoot实现动态定时任务,是Springboot做的动态定时任务,可以暂停,恢复,添加,删除,等操作
SpringBoot定时发送邮件示例代码;SpringBoot定时发送邮件示例代码SpringBoot定时发送邮件示例代码SpringBoot定时发送邮件示例代码SpringBoot定时发送邮件示例代码
微信公众号模板消息推送SpringBoot定时任务版本-VxMessage
SpringBoot定时任务,解析 fixedRate,fixedDelay, initialDelay的详细功能
主要为大家详细介绍了SpringBoot实现定时任务和异步调用,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
使用springboot 构建的 spring task 定时任务,采用异步任务形式,防止任务堵塞.
Springboot整合Quartz实现定时任务数据库动态配置,新增任务、修改cron表达式、暂停任务、恢复任务、删除任务等操作