Spring Batch的2.2 JavaConfig [英] Spring batch 2.2 JavaConfig

查看:351
本文介绍了Spring Batch的2.2 JavaConfig的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让Spring Batch的2.2 JavaConfig工作。

I'm trying to get Spring Batch 2.2 working with JavaConfig.

现在他们有一个 @EnableBatchProcessing 注释,设置了很多东西。
默认的注释使用的数据源为它的就业数据,但我们不希望保存这些数据,并且不希望创建表吧。文档说一些关于自定义,但我一直没能得到它的工作:

Nowadays they have a @EnableBatchProcessing annotation that sets up a lot of things. Default that annotation uses a datasource for its job data, but we don't want to save this data and don't want to create the table for it. The documentation says something about customizing but I have not been able to get it working:


  • 的用户必须在配置提供了一个数据源在上下文中的豆,否则实施 BatchConfigurer 类本身,例如:

  • The user has to provide a DataSource as a bean in the context, or else implement BatchConfigurer in the configuration class itself, e.g.:

公共类的AppConfig扩展DefaultBatchConfigurer {

在我们的旧版本,我们已经能够使用 MapJobRepositoryFactoryBean 类,以便它在内存中保存的所有数据。反正是有使用全JavaConfig方式,而不是定义一个数据源?我已经无法得到它的工作。

In our older version we've been able to use MapJobRepositoryFactoryBean class so it keeps all its data in memory. Is there anyway to use the full JavaConfig way and not define a DataSource? I've not been able to get it working.

即使我定义两个数据源(一个HSQL在内存中,从来没有被使用),我们真正的Oracle数据源,这是行不通的,因为它发现两个数据源,而不是一个。

Even if I define two data sources (one HSQL in-memory that never gets used) and our real Oracle datasource it does not work because it finds two data sources instead of one.

任何人有一个想法如何得到这个工作?或者是唯一的解决办法要回了XML的方式配置此?

Anyone have an idea how to get this working? Or is the only solution going back to configuring this in the XML way?

推荐答案

假设没有其他文物需要一个DataSource,你可以使用Java的配置没有一个数据源创建上下文。要做到这一点,你的配置需要正如你指出来扩展DefaultBatchConfigurer。在那里,你会重写两个方法,createJobRepository()和的setDataSource()。下面是一个例子上下文(它没有定义的作业或步骤,但它正确地自举的所有相关Bean)。

Assuming that no other artifacts require a DataSource, you can use java config to create a context without a DataSource. To do that, your configuration will need to extend DefaultBatchConfigurer as you point out. In there, you'll override two methods, createJobRepository() and setDataSource(). Below is an example context (it doesn't define a job or steps, but it bootstraps all the related beans correctly).

@Configuration
@EnableBatchProcessing
public static class BatchConfiguration extends DefaultBatchConfigurer {

    @Override
    protected JobRepository createJobRepository() throws Exception {
        MapJobRepositoryFactoryBean factory = 
            new MapJobRepositoryFactoryBean();
        factory.afterPropertiesSet();
        return  (JobRepository) factory.getObject();
    }

    @Override
    @Autowired
    public void setDataSource(DataSource dataSource) {
        if(dataSource != null) {
            super.setDataSource(dataSource);
        }
    }

    @Bean
    public DataSource dataSource() {
        return null;
    }
}

我的确认为简化这将是一个非常有用的功能,并把它添加到吉拉。您可以跟踪它在这里的进展:<一href=\"https://jira.springsource.org/browse/BATCH-2048\">https://jira.springsource.org/browse/BATCH-2048

这篇关于Spring Batch的2.2 JavaConfig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆