【问题标题】:spring batch job to execute method in manager春季批处理作业在管理器中执行方法
【发布时间】:2014-06-30 17:13:04
【问题描述】:

我是春季批次的新手,非常感谢您的帮助。到目前为止,我有两个春季批处理作业。它们都有一个项目阅读器(sqls select)和一个项目编写器(sql insert)。

他们看起来像这样......

<job id="job-daily-tran-counts" xmlns="http://www.springframework.org/schema/batch">
    <step id="job-daily-tran-counts-step1">
        <tasklet>
            <chunk 
                reader="dailyTranCountJdbcCursorItemReader" 
                writer="dailyTranCountItemWriter" 
                commit-interval="1000" />
        </tasklet>
    </step>
</job>

现在我想编写一个简单的批处理作业来在我的一个管理器中执行一个方法,该方法会刷新许多值映射列表的缓存。我认为项目阅读器和项目作者并不真正适合。我应该如何构建这个批处理作业?

更具体地说,我有一个名为 LovManagerImpl 的类,我需要从 spring 批处理中执行 afterPropertiesSet 方法。最好的方法是什么?

public class LovManagerImpl implements LovManager,InitializingBean {

    /**
     * The list of values data access object factory
     */
    @Autowired
    public LovDaoFactory lovDaoFactory;

    /* (non-Javadoc)
     * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
     */
    public void afterPropertiesSet() throws ReportingManagerException {
        Map<String,LovDao> lovDaoMap = lovDaoFactory.getLovDaoMap();
        for (Map.Entry<String,LovDao> entry : lovDaoMap.entrySet()){         
            String code = (String)entry.getKey();
            LovDao dao = (LovDao)entry.getValue();
            dao.getLov(code);
        }   
    }

谢谢

【问题讨论】:

    标签: spring-batch


    【解决方案1】:

    使用小任务;请参考Can we write a Spring Batch Job Without ItemReader and ItemWriter解答。
    对于您的特定情况 - 重用现有服务方法 - 使用 MethodInvokingTaskletAdapter

    【讨论】:

    • 谢谢。我在 MethodInvokingTaskletAdapter 上进行了搜索,它运行良好。我所做的只是在我的服务 bean 上放置一个限定符,然后指定 targetBean 和 targetMethod。真不错!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-17
    • 1970-01-01
    • 1970-01-01
    • 2014-12-21
    • 2021-12-28
    • 2012-10-19
    相关资源
    最近更新 更多