4

Is there any example of using spring xd with pure java config (no xml). I created a simple tasklet, jarred the same (whojob.jar) and put it into the lib folder. The xml config is below. I put this in a file called whojob which is in the modules/job folder and also jarred with my whojob.jar. When I try to create a job:- (:>job create --name mywhojob --definition "whojob") I get the error : Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.integration.config.TransformerFactoryBean#0': Cannot create inner bean 'org.springframework.xd.dirt.plugins.job.JobLaunchRequestTransformer#0' of type [org.springframework.xd.dirt.plugins.job.JobLaunchRequestTransformer] while setting bean property 'targetObject'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.xd.dirt.plugins.job.JobLaunchRequestTransformer#0' defined in class path resource [META-INF/spring-xd/plugins/job/job-module-beans.xml]: Cannot resolve reference to bean 'jobFactoryBean' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobFactoryBean': FactoryBean threw exception on object creation; nested exception is java.lang.IllegalStateException: No Batch Job found in registry for the provided key 'mywhojob.job'. My xml config is below. If possible I would like to have a pure java solution. Thanks

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
    xmlns:batch="http://www.springframework.org/schema/batch"
xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/integration
    http://www.springframework.org/schema/integration/spring-integration.xsd
    http://www.springframework.org/schema/batch
    http://www.springframework.org/schema/batch/spring-batch.xsd">

<batch:job id="whojob">
    <batch:step id="whojobStep">
        <batch:tasklet ref="whojobXDTasklet" />
    </batch:step>
</batch:job>

<bean id="whojobXDTasklet"
    class=" com.auction.data.batch.job.WhoTasklet" >
    <property name= "who" ref="whoBean"/> 
</bean>

<bean id="whoBean"
    class="com.auction.data.batch.service.Who" >

</bean>

    </beans>
user3304825
  • 107
  • 2
  • 12
  • As of right now, I don't believe that java config is supported by XD for job definitions within Spring XD. However, that isn't the cause of your error. What version of XD are you using? Earlier versions of Spring XD required that the id of the job within the XML definition be job which is not what you have here. I'd start with that. – Michael Minella Mar 07 '14 at 15:05
  • Hi Michael I am using XD version 1.0.0.M5. I am not too familiar with the framework. I managed to get a stand alone spring batch project working (which had all java config). I then converted the java config to its xml version. I have a reference to JobRepositoryFactoryBean and then converted the same to a spring xd module. – user3304825 Mar 07 '14 at 23:33
  • Please see https://github.com/spring-projects/spring-xd/issues/1216 for a related ticket. – btiernay Jan 07 '15 at 02:44

1 Answers1

1

Here is a sample that uses XD job with the batch tasklet defined in an external jar file.

https://github.com/ilayaperumalg/spring-xd-batch-sample

To create jar, from the repo root directory, just run: ./gradlew build

To make it easier, I have also copied the job module "myjob" (which uses the above tasklet) into the repo. You can just copy this 'myjob' into your $XD_HOME/modules/job/.

Give it a try using XD version M6 or the latest master, and let us know if you have any question.

Ilayaperumal Gopinathan
  • 4,099
  • 1
  • 13
  • 12