【问题标题】:Spring boot Schedule payment on several months and specific date春季启动计划付款在几个月和特定日期
【发布时间】:2018-09-18 17:48:56
【问题描述】:

在 Spring Boot 应用程序中安排任务对我来说是新的。我已经阅读了几篇关于它的帖子,但无法将它们放在一起。 在我的情况下,客户将他的付款日期设置为某个日期,将他的付款日期设置为将来的某个日期,以及每月的付款日期,例如每月 25 日。 因此,如果我将日期设置为 01-04-2018 - 30-08-2018 并每 25 日支付一天,我的计划任务应在每个月的 25 日执行一次,例如 25-04、25-05、25-06 , 25-07 和 25-08。我将在下面发布我的实体模型。我无法为此编写任何工作服务。请帮忙。

@Column(name = "name")
private String name;
@Column(name = "amount")
private BigDecimal amount;
@Column(name = "outcome")
private Boolean outcome;
@Column(name = "currency")
@Convert(converter = CurrencyConverter.class)
private Currency currency;
@Column(name = "comment")
private String comment;
@Column(name = "dimension")
@Convert(converter = DimensionConverter.class)
private Dimension dimension;
@Column(name = "type_id")
@Convert(converter = ExpenseTypeConverter.class)
private ExpenseType expenseType;


@Column(name = "finished_payment", nullable = true)
private Boolean finishedExpense;


@Column(name = "period_from", nullable = true)
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="dd-MM-yyyy")
private Date periodFrom;
@Column(name = "period_to", nullable = true)
@JsonFormat(shape=JsonFormat.Shape.STRING, pattern="dd-MM-yyyy")
private Date periodTo;
@Column(name = "pay_day", nullable = true)
private int payDay;

【问题讨论】:

    标签: java spring cron schedule


    【解决方案1】:

    在 Spring Boot 中使用 @EnableScheduing..

    @Scheduled(fixedDelay = 300000)
    //300000=5 mins.
    public void startQuery(){
        try{
            /Schedule something here
        }catch(Exception e){
    
        }
    }
    

    您也可以使用 Cron 表达式代替 fixedDelay
    对于您的用例,您应该使用 Quartz+Spring boot 。在此处阅读文档.. https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-quartz.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-08-01
      • 2014-09-14
      • 2021-03-02
      • 2020-03-06
      • 2013-12-24
      • 2020-06-01
      • 2019-04-13
      • 1970-01-01
      相关资源
      最近更新 更多