Announcement Announcement Module
No announcement yet.
Add Custom Meta Data to a Spring Batch job Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Add Custom Meta Data to a Spring Batch job

    How do I add custom meta data to a Spring Batch job? We are currently using Spring batch to kick off jobs from our web app. I want to be able to store the user who kicked off the job along w/ the timestamp and retrieve that once I query the job repo. I'm using HibernateCursorItemReader as my reader and implemented ItemWriter to persist to the database.
    This is my job

    <batch:job id="sendToJournal">
    <batch:step id="step1">
    <batch:tasklet transaction-manager="txnManager">
    <batch:chunk reader="journalReader" writer="journalWriter"

    What is the best way to go about this?

  • #2
    journalReader is common Spring Bean. Why can't you inject something like:

    UserService userService;
    into your reader/writer? The given service should provide you with a user name taken from your application internals.

    In general case we can't guess what is "user" in your application, how it is provided to your application and how it is managed. If you want to access user given by HTTP request, then you can use (one need to populate the current HTTP request to thread either by using org.springframework.web.servlet.DispatcherServlet or org.springframework.web.context.request.RequestCon textListener or org.springframework.web.filter.RequestContextFilte r):

    import org.springframework.web.context.request.RequestContextHolder;
    import org.springframework.web.context.request.ServletRequestAttributes;
    ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getRemoteUser()
    but that has nothing to do with String Batch. Consider asking in another forum.


    • #3
      Add Custom Meta Data to a Spring Batch job


      I want to store the user in case another user tries to kick off the job. If its currently running, i want to display to user2 that user1 is running the job. I figured out a way to do this.