Results 1 to 3 of 3

Thread: Database input and email output in Spring batch

  1. #1
    Join Date
    Jan 2008
    Posts
    21

    Default Database input and email output in Spring batch

    Hi,

    I need to create a batch job which takes input from database and gives output to email.

    I know how to do the input from database but I am not sure how to output it to an email

    Can you please tell whether it's posible or not.If that's posible can you also send me the sample code for sending the output in an email.

    Thanks,
    Aruna

  2. #2
    Join Date
    Dec 2006
    Posts
    1,061

    Default

    It is definitely possible, and you can find many sample jobs on how to read from a database table by downloading the Spring Batch source. There currently isn't a spring batch abstraction for mail, since Spring proper already contains one:

    http://static.springframework.org/sp...ence/mail.html

    Please add a new jira issue if this isn't sufficient in a batch scenario. The only problem I could see would be one of transactions, since you can't really roll back an email, but since accidentally sending more than one email wouldn't be a huge issue, I'm not sure this will be a problem.

  3. #3

    Default

    Here is a snippet for a simple mail sender ItemWriter:


    Code:
    public class MailSenderWrapper implements ItemWriter {
    
        private MailSender mailSender;
            
        public void setMailSender(MailSender mailSender) {
            this.mailSender = mailSender;
        }
    
        public void write(Object item) {
            if (item instanceof SimpleMailMessage) {
                mailSender.send((SimpleMailMessage)item);
            } else if (item instanceof SimpleMailMessage[]) {
                mailSender.send((SimpleMailMessage[])item);
            } else {
                throw new IllegalArgumentException("Item should be either SimpleMailMessage or array of SimpleMailMessage objects");
            }
        }
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •