开发者

How can I get started with Spring Batch? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.

Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.

Closed 9 years ago.

Improve this question

I'm trying to learn Spring Batch, but the startup guide is very confusing. Comments like

You can get a pretty good idea about how to 开发者_如何学JAVAset up a job by examining the unit tests in the org.springframework.batch.sample package (in src/main/java) and the configuration in src/main/resources/jobs.

aren't exactly helpful. Also I find the Sample project very complicated (17 non-empty Namespaces with 109 classes)! Is there a simpler place to get started with Spring Batch?


A few pointers:

  • Spring Batch HelloWorld
  • Spring Batch "Hello World" 1
  • Spring Batch "Hello World" 2
  • A first look at Spring Batch (via archive.org)
  • A first look at Spring Batch, part 2 (via archive.org)
  • Spring Batch : Hello World!


I agree that the user guide is very confusing (compared to the Spring Core user guide at any rate). It doesn't adequately address some very important gotchas that you will run up against in any moderately complex batch scenario.

Important things that you should drill down into as a new starter, and decide your requirements for are,

  • configuration of exceptions (when to skip, when to fail, when to retry)
  • use of execution context to maintain state (eg when to use step execution context vs job execution context).
  • general maintenance of state (use the step scope, especially for input parameters)

It is worth persevering however. Batch programming is very different to other server side styles and greatly benefits from the usual Spring "pattern abstraction" approach.


Before you jump on the Spring Batch wagon, you may want to read what SO's own cletus has to say about its shortcomings:

http://www.cforcoding.com/2009/07/spring-batch-or-how-not-to-design-api.html.

I recently evaluated Spring Batch, and quickly rejected it once I realized that it added nothing to my project aside from bloat and overhead. Spring Batch may eventually become an OK product (much like EJBs got it right this time around), but at the moment it looks suspiciously like a solution in search of a problem.


I recently gave Spring Batch a real try. I'll say that in my implementation, I used an in-memory repository (because restarts and retries were not a priority in my project's circumstance), but I can appreciate what Richard says about the JobRepository: you basically have to dig deep to find the database schema.

For Spring Batch 2.1, they do provide some documentation on the repository: http://static.springsource.org/spring-batch/reference/html/metaDataSchema.html, including discussions about how to deal with database-specific implementations. The DDL for creating the tables are located in the core Spring Batch JAR file:

spring-batch-core-2.1.0.RELEASE.jar:/org/springframework/batch/core/*.sql

Scripts are present for DB2, Derby, H2, HSQLDB, MySQL, Oracle 10g, PostgreSQL, MS SQL, and Sybase.


In this tutorial, we will create a simple Spring Batch application to demonstrate how to process a series of jobs where the primary purpose is to import a lists of comma-delimited and fixed-length records. In addition, we will add a web interface using Spring MVC to teach how to trigger jobs manually, and so that we can visually inspect the imported records. In the data layer, we will use JPA, Hibernate, and MySQL.

  1. http://krams915.blogspot.jp/2012/02/spring-batch-tutorial-part-1.html
  2. http://krams915.blogspot.jp/2012/02/spring-batch-tutorial-part-2.html
  3. http://krams915.blogspot.jp/2012/02/spring-batch-tutorial-part-3.html
  4. http://krams915.blogspot.jp/2012/02/spring-batch-tutorial-part-4.html


https://github.com/langmi/spring-batch-examples

This contains some pretty good basic examples.


I've just started looking at Spring Batch as a possible replacement to our in-house batch framework. Actually creating a batch server with the capability to schedule Jobs and a JMX interface on top to provide an overview of running/previously ran job instances has taken little more than a day. However, like Caoilte, I am finding problems with the documentation. The main one, and one which isn't in the documentation or the javadocs, is what tables are required by the JobRepository. The default is to have a database-persistence JobRepository, which is one of the requirements of my new server, but I cannot find any mention of the tables required. I've had to search Google high and low for any mention of them (If they are in the documentation, then I will gladly put salt on my humble pie).

I think actually creating a batch to run within Spring Batch is a rather complex task, given the vast array of configuration options available to you. This is a strength in my eyes. It provides opportunities to configure complex batch tasks in xml, which I have yet to find in any other batch framework (that I know of). But if you really did not want to harness the power of Spring Batch, why not just create a job with a single tasklet step (But then you have to ask yourself if its worth the overhead).


Too bad you guys abandoned it, the framework is actually really great. But if anybody else needs a quick start try: Spring Batch Quick Start

/Anatoly

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜