【问题标题】:Database reading calls from spring item processor来自弹簧项目处理器的数据库读取调用
【发布时间】:2015-02-10 05:48:04
【问题描述】:

我是 Spring Batch 的新手。

我只是想知道我们是否可以从 Itemprocessor 进行数据库调用(jdbccursoritemreader)?

我需要读取数据库(ItemReader),发送记录以进行处理(ItemProcessor),在处理时我需要调用其他数据库(就像参考数据一样)来更新我从 ItemReader 获得的记录最后将最终的发送给作家。

感谢任何解决方法和建议。

谢谢。

【问题讨论】:

    标签: spring batch-processing


    【解决方案1】:

    是的,你可以这样做。

    您需要在处理器中注入一个类来为您读取数据库。为简单起见,我可能会使用 JdbcTemplate。

    类似这样的:

    public class MyProcessor implements ItemProcessor<Foo, Bar> {
    
      private JdbcTemplate jdbcTemplate;
    
      @Override
      public Foo process(Bar bar) throws Exception {
        //use JdbcTemplate here
      }
    
      public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
      }
    
    }
    

    当你配置你的处理器时,注入 JdbcTemplate:

    <bean class="com.example.MyProcessor" id="myProcessor">
      <property name="jdbcTemplate" ref="jdbcTemplate"/>
    </bean>
    

    【讨论】:

    • 嗨,尼尔,感谢您的回复。我将此解决方案保留为PLAN B。我认为spring批处理配置本身是否提供这样的解决方案,例如itemReader1从主数据库读取数据并发送到itemprocessor1,itemReader2从参考数据库读取数据并发送到itemprocessor2并使用compositeitemprocessor club这两个结果,处理并将其发送给单个或多个 Itemwriters。可以这样吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 2018-08-24
    • 1970-01-01
    • 2014-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多