Announcement Announcement Module
Collapse
No announcement yet.
Dynamic Job Creation in Spring-Batch-How to set bean's property value at runtime Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Dynamic Job Creation in Spring-Batch-How to set bean's property value at runtime

    Hi Everyone,

    I am new to spring batch and I have a requirement as mentioned below

    Requirement :

    I have a UI,where the client can enter property details of a Email Action,File Mover Action or File Copy Action,etc.
    The client will drag the actions(ex.Email Action,File Mover Action) elements(rectangle box in UI) from the front-end and
    enter the properties and do a save.For example,for a File Copy Action element,the user can enter the below:
    -- host,file_name,input_location,output_location.
    Once the client save the details,we have to generate a Job.xml and execute it in Spring-Batch

    snapshot of our Job.xml is like below:
    ** Where the value="{...}" will come from UI or database

    <beans ...>
    .......
    ......
    <bean id="copyFile" class="com.email.FileCopyActionTasklet" >
    <property name="host" value="{host}"/>
    <property name="file_name" value="{file_name}"/>
    <property name="input_location" value="{input_location}"/>
    <property name="output_location" value="{body_msg}"/>

    </bean>
    <bean id="dynamicJobParameters" class="com.springbatch.DynamicJobParameters" />
    <batch:job id="copyJobId" job-repository="jobRepository" incrementer="dynamicJobParameters">
    <batch:step id="step0">
    <batch:tasklet ref="copyFile" transaction-manager="jobRepository-transactionManager" />
    </batch:step>
    </batch:job>
    </beans>

    Could anybody please help me out ,how can I achieve this.We have to set the property value at runtime.

    Please let me also know which below approach shall I take :

    1.
    GenericApplicationContext genericContext = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(genericContext );
    xmlReader.loadBeanDefinitions(new FileSystemResource("Job.xml");
    genericContext.refresh();

    Or

    2.the one posted that was posted earlier in this forum :

    Dynamic Job Creation

    Thanks in Advance

    Shyam
    Last edited by shyambaishya; Jul 31st, 2012, 08:04 AM.

  • #2
    ** Where the value="{...}" will come from UI or database
    Why not use a ItemReader?

    Comment


    • #3
      Hi traduz,
      Shyambaishya and me working toghter so let me explain what is the scenario

      We want to copy file/files from one machine to another machine using Linux command ( environment ).

      1. Copy file/files using Linux COPY command from one machine A to another machine B.
      1. The execution of COPY command is itself a remote SSH command from another machine C.
      3. We are not manipulation the data, we are just coping it as it is.
      4. Copying from one machine to another machine in Linux environment required user authentication and authorization.
      5. We are using org.springframework.batch.core.step.tasklet.System CommandTasklet to accomplish this.

      For these reasons we are using SystemCommandTasklet job other than chunk oriented job

      Thing is that every time the UI submit requests, we got new values for source_machine_id, source_path, destination_machine_id, destination_path to copy file/files.
      Last edited by paragflume; Aug 1st, 2012, 01:17 AM.

      Comment


      • #4
        Can't you use a listener?
        Reference: http://static.springsource.org/sprin...aToFutureSteps

        Comment


        • #5
          Hi,

          Thanks for you prompt response.

          Actually,we don't need to read the data every time from a source , neither need to process a large volume of data.We need to only get the data from UI ,set it in Step scope and then run the Job.

          For example, we have to copy a file from one location to another location in a different PC.Once this is done,send a mail to the administrator.So, in this case, we have two task->File Copy task and Send Email Task.We have create a Job with this two task,where the client will set the value from UI(for both File Copy as well as email addresses).

          In this case, I believe we have to use Tasklet as below:

          <batch:job id="fieCopyAndEmailJob" job-repository="jobRepository" >
          <batch:step id="step0" next="step1">
          <batch:tasklet ref="fileCopy" transaction-manager="jobRepository-transactionManager" />
          </batch:step>
          <batch:step id="step1">
          <batch:tasklet ref="email" transaction-manager="jobRepository-transactionManager" />
          </batch:step>
          </batch:job>

          Where,I want to set the ref="fileCopy" and "email" bean property has to set from UI.

          Can't spring-batch provide any solution for this ?

          Any help/suggestion would be much appreciated, as I am stuck with further development.

          Thanks and Regards
          Shyam
          Last edited by shyambaishya; Aug 2nd, 2012, 06:04 AM.

          Comment


          • #6
            See if this helps you my friend: http://static.springsource.org/sprin...ml#taskletStep

            Comment

            Working...
            X