Announcement Announcement Module
Collapse
No announcement yet.
Job definition using annotations Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Job definition using annotations

    Hi,

    I've not found any documentation or examples of defining jobs using annotations.

    Is it possible to define jobs with annotation and remove all xml configurations?

    Spring 3.0.5
    Spring-Batch-2.1.7

  • #2
    as far I know, no (at least easily). You can use Java configuration in Spring 3.0 to create your jobs, but you'll need to know what the tags from the batch namespace are actually doing behind the scenes.

    Comment


    • #3
      then we should have annotation based jobs support from the framework.

      Comment


      • #4
        If you have any concrete suggestions for how this would look, please sketch something here, or contribute the code to the project on github. New feature requests can also be created at https://jira.springsource.org/browse/BATCH. More detail would be nice.

        Comment


        • #5
          Given all of the "infrastructure" that comes along with Spring Batch (repository, launch, task executor, registry, etc etc), I don't see how annotations really make things a whole lot better. You'd either need to have accept a bunch of defaults, or have a ton of annotations.

          As it stands now, most of the time, you don't even create your own job class, you just configure existing spring beans to do the work.

          Would the following make sense?

          @Job
          class MyClass

          I don't think so, because then you need to relate that job to everythign else (steps, readers, writers, launchers, repositories).

          Perhaps we peel this onion with something simplers, annotations for ItemReader, ItemProcessor, and ItemWriter for people writing custom components.

          Comment


          • #6
            I think the best chance of using Java to configure a job is to have a fluent builder in the framework, so user can do something like this:

            Code:
            @Bean
            public Job myJob() {
              JobBuilder builder = JobBuilder.start(step1()).next(step2());
              builder.on("FAILED").to(step3());
              builder.on("*").end();
              return builder.build();
            }
            Other ideas more than welcome. But fundamentally I think XML is a good form for declaring state machines (like a Job).

            Comment


            • #7
              Yes. it is true that majority of jobs that we are using xml are self sufficient and we don't have to create our own jobs. As of now, I don't have any suggestions as to how the annotations look like.

              However, I will keep this in mind and will write when I encounter any scenario or good use case for it. Thank you for replying to the idea.

              Comment

              Working...
              X