Announcement Announcement Module
Collapse
No announcement yet.
Database input and email output in Spring batch Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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");
              }
          }
      }

      Comment

      Working...
      X