spring cron expression must consist of 6 fields 已解决,亲测有效

使用spring3.1 以注解的形式配置定时任务

当我想把定时任务的时间放入配置文件里去,然后动态获取的时候,总是报
cron expression must consist of 6 fields (found 1 in ${job.schedule})

百思不得其解
通过google在下面这个网址下找到解决办法

https://stackoverflow.com/questions/36418882/scheduled-throwing-exception-for-cron-expression

我的定时任务类:

/**
 * 
 */
package com.dounion.bas.util;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import com.dounion.bas.business.BasSyndataBusiness;

/**
 * @author Administrator
 *
 */
@Configuration //1.主要用于标记配置类,兼备Component的效果。
@EnableScheduling // 2.开启定时任务
@PropertySource("classpath:/bas.properties")
public class TimerTask_bas{
	
	/** 注入行动Dao类 **/
	@Autowired
    private BasSyndataBusiness basSyndataBusiness;
	
	@Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }
	 
	/**
	 * 
	 * author: kangyu
	 * 2018-11-26 下午5:32:29
	 * @Description: // 查询同步日志表发送给库点(每隔1分钟触发一次)
	 */
	@Scheduled(cron = "${job.schedule}")
	public void sendDataToLibraryPoint() {
		basSyndataBusiness.sendDataToLibraryPoint();
	}
	
	@Scheduled(cron = "${job.schedule}")
	public void dealDataInRedis() {
		basSyndataBusiness.dealDataInRedis();
	}

}

TimerTask_bas类主要加了以下几行才解决如上bug

	@Bean
    public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
        return new PropertySourcesPlaceholderConfigurer();
    }

配置文件bas.properties是这么写的job.schedule = 0 */1 * * * ?
application.xml主要代码:

	<context:annotation-config />
	<context:component-scan base-package="com.dounion" />
	<aop:aspectj-autoproxy proxy-target-class="true" />
  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值