【问题标题】:Dropwizard Sundial Schedueled task with Hibernate object带有 Hibernate 对象的 Dropwizard Sundial 计划任务
【发布时间】:2018-08-28 14:19:43
【问题描述】:

我的 dropwizard 项目中有这个日晷任务:

@SimpleTrigger(repeatInterval = 10, timeUnit = TimeUnit.SECONDS)
public class GitlabImporter extends Job {

private static BranchDAO branchDAO;

    @Override
    @ExceptionMetered
    public void doRun() throws JobInterruptException {

        branchDAO = (BranchDAO) SundialJobScheduler.getServletContext().getAttribute("BranchDAO");

        String jobId = UUID.randomUUID().toString();

        try {
            ...
            log.info(branches.toString());
        } catch (Exception e) {
            log.error(e.getLocalizedMessage());
        }
    }
}

我尝试在 Sceduler 任务中使用我的 DAO,我想按照日晷文档如何加载对象,但它似乎不起作用。 在我的日晷任务中使用 Hibernate 项目的正确方法是什么?

谢谢

【问题讨论】:

    标签: java hibernate dropwizard jdbi sundials


    【解决方案1】:

    实现此目的的一种方法是在 YourDropwizardApplication 类的 run() 方法中设置 BranchDAO 属性 -

    environment.getApplicationContext().setAttribute("BranchDAO", new BranchDAO());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-19
      • 2023-04-05
      • 1970-01-01
      • 1970-01-01
      • 2019-12-09
      • 1970-01-01
      • 2015-04-11
      相关资源
      最近更新 更多