Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7800545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:40:22+00:00 2026-06-02T00:40:22+00:00

I would like to use Spring batch for a batch application. I already have

  • 0

I would like to use Spring batch for a batch application. I already have a domain model designed following DDD. My question is how batch processing (in my case, using Spring batch) fits with DDD?

For example, I have an aggregate root A and one of its children is the entity B. A has a list of one or more Bs. The batch application receives a file when each line corresponds to an operation (add, delete…) on the list of Bs. In my aggregate root A, I have one method for each operation (e.g. addB, delB…). Using Spring batch, which ItemWriter should I use? I don’t think a JdbcBatchItemWriter is appropriated since I should deal with the data only through the domain. Are there best practices concerning the use of DDD with batch processing?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:40:24+00:00Added an answer on June 2, 2026 at 12:40 am

    I don’t pretend to know what exactly the best practice for this is, but this is how I’d do it, considering your design goals. Instead of A and B, say we have a File object, your aggregate, which contains many lines:

    class File {
        public void addLine(Line l) {/* implementation here*/}
        public void removeLine(Line l) {/* implementation here*/}
    }
    
    class Line {
    }
    

    Have your Reader/Processors return LineOperations, encapsulating your line (which you just read) and whether you are doing an add/remove/other:

    interface LineOperation {
        public void execute(File file);
    }
    
    class DeleteOperation implements LineOperation {
    
        private Line line;
    
        private DeleteOperation(Line line) {
            super();
            this.line = line;
        }
    
        public void execute(File file) {
            file.removeLine(line);
        }
    }
    

    Implementations of the AddOperation and whatever else you may require are left to the imagination.

    Next, we’ll be passing the the LineOperations to your writer. Your writer performs the operation on the Aggregate File, and then uses the FileRepository to write the aggregate.

    class LineOperationWriter implements ItemWriter<LineOperation>, StepExecutionListener {
    
        @Autowired;
        FileRepository fileRepo;
    
        private Long fileId;
    
        public void write(List<? extends LineOperation> items) throws Exception {
    
            File file = fileRepo.find(fileId);
            for (LineOperation lineOperation : items) {
                lineOperation.execute(file);
            }
            fileRepo.persist(file);
    
        }
    
        @Override
        public void beforeStep(StepExecution stepExecution) {
            this.fileId = (Long) stepExecution.getJobExecution().getExecutionContext().get("fileId");
        }
    
        @Override
        public ExitStatus afterStep(StepExecution stepExecution) {
            return null;
        }
    }
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Spring Security 3.0.3.RELEASE. I would like to create a custom authentication processing
I currently have Spring configured to use HSQL, but I would like to use
I have a web application using JPA and JTA with Spring. I would like
I am using Spring Security 3.0.6. for modularity reasons, I would like to use
I would like to use KVO in the following context: 1) In touchesBegan:withEvent: I
I would like to use a COM object in my application. How can I
I would like to be able to use Spring using setter injection into Scala
I would like to use jsf annotations and some spring annotations to inject a
I would like use Spring.NET for IoC , DI, AOP and Caliburn as MVVVM
I would like to use direct field access for command objects in Spring MVC

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.