asynchronous - spring batch AsynchJob Launcher ,Error in setting job repo -
hi below configuration creating asynchlob launcher
<bean id="joblauncher" class="org.springframework.batch.core.launch.support.simplejoblauncher"> <property name="jobrepository" ref="&jobrepository" /> <property name="taskexecutor" ref="taskexecutor" /> </bean> <bean id="taskexecutor" class="org.springframework.core.task.simpleasynctaskexecutor" /> <bean id="jobrepository" class="org.springframework.batch.core.repository.support.mapjobrepositoryfactorybean" />
i'm getting below error
error creating bean name 'batchjoblauncher': injection of autowired dependencies failed; nested exception org.springframework.beans.factory.beancreationexception: not autowire field: private org.springframework.batch.core.launch.support.simplejoblauncher com.batch.launcher.batchjoblauncher.asyncjoblauncher; nested exception org.springframework.beans.factory.beancreationexception: error creating bean name 'joblauncher' defined in servletcontext resource [/web-inf/batchconfig.xml]: initialization of bean failed; nested exception org.springframework.beans.conversionnotsupportedexception: failed convert property value of type 'org.springframework.batch.core.repository.support.mapjobrepositoryfactorybean' required type 'org.springframework.batch.core.repository.jobrepository' property 'jobrepository'; nested exception java.lang.illegalstateexception: cannot convert value of type [org.springframework.batch.core.repository.support.mapjobrepositoryfactorybean] required type [org.springframework.batch.core.repository.jobrepository] property 'jobrepository': no matching editors or conversion strategy found ..... caused by: org.springframework.beans.conversionnotsupportedexception: failed convert property value of type 'org.springframework.batch.core.repository.support.mapjobrepositoryfactorybean' required type 'org.springframework.batch.core.repository.jobrepository' property 'jobrepository'; nested exception java.lang.illegalstateexception: cannot convert value of type [org.springframework.batch.core.repository.support.mapjobrepositoryfactorybean] required type [org.springframework.batch.core.repository.jobrepository] property 'jobrepository': no matching editors or conversion strategy found @ org.springframework.beans.beanwrapperimpl.convertifnecessary(beanwrapperimpl.java:476) [spring-beans-4.1.6.release.jar:4.1.6.release] @ org.springframework.beans.beanwrapperimpl.convertforproperty(beanwrapperimpl.java:512) [spring-beans-4.1.6.release.jar:4.1.6.release] @ org.springframework.beans.beanwrapperimpl.convertforproperty(beanwrapperimpl.java:506) [spring-beans-4.1.6.release.jar:4.1.6.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.convertforproperty(abstractautowirecapablebeanfactory.java:1523) [spring-beans-4.1.6.release.jar:4.1.6.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.applypropertyvalues(abstractautowirecapablebeanfactory.java:1482) [spring-beans-4.1.6.release.jar:4.1.6.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.populatebean(abstractautowirecapablebeanfactory.java:1222) [spring-beans-4.1.6.release.jar:4.1.6.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.docreatebean(abstractautowirecapablebeanfactory.java:537) [spring-beans-4.1.6.release.jar:4.1.6.release] ... 54 more caused by: java.lang.illegalstateexception: cannot convert value of type [org.springframework.batch.core.repository.support.mapjobrepositoryfactorybean] required type [org.springframework.batch.core.repository.jobrepository] property 'jobrepository': no matching editors or conversion strategy found @ org.springframework.beans.typeconverterdelegate.convertifnecessary(typeconverterdelegate.java:287) [spring-beans-4.1.6.release.jar:4.1.6.release] @ org.springframework.beans.beanwrapperimpl.convertifnecessary(beanwrapperimpl.java:461) [spring-beans-4.1.6.release.jar:4.1.6.release] ... 60 more
i tried without & also.
error this
13:58:59,346 warn [org.springframework.web.context.support.xmlwebapplicationcontext] (serverservice thread pool -- 58) exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.beancreationexception: error creating bean name 'jobbuilders' defined in class path resource [org/springframework/batch/core/configuration/annotation/simplebatchconfiguration.class]: bean instantiation via factory method failed; nested exception org.springframework.beans.beaninstantiationexception: failed instantiate [org.springframework.batch.core.configuration.annotation.jobbuilderfactory]: factory method 'jobbuilders' threw exception; nested exception java.lang.classcastexception: org.springframework.batch.core.repository.support.mapjobrepositoryfactorybean$$enhancerbyspringcglib$$99e29281 cannot cast org.springframework.batch.core.repository.jobrepository @ org.springframework.beans.factory.support.constructorresolver.instantiateusingfactorymethod(constructorresolver.java:599) [spring-beans-4.1.6.release.jar:4.1.6.release] @ org.springframework.beans.factory.support.abstractautowirecapablebeanfactory.instantiateusingfactorymethod(abstractautowirecapablebeanfactory.java:1119)
here working example made http://www.mkyong.com/spring-batch/spring-batch-hello-world-example/ , tested on wildfly 9.
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:batch="http://www.springframework.org/schema/batch" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd "> <bean id="report" class="report" scope="prototype" /> <bean id="jobrepository" class="org.springframework.batch.core.repository.support.mapjobrepositoryfactorybean"> <property name="transactionmanager" ref="transactionmanager" /> </bean> <batch:job id="helloworldjob"> <batch:step id="step1"> <batch:tasklet> <batch:chunk reader="cvsitemreader" writer="xmlitemwriter" commit-interval="10"> </batch:chunk> </batch:tasklet> </batch:step> </batch:job> <bean id="joblauncher" class="org.springframework.batch.core.launch.support.simplejoblauncher"> <property name="jobrepository" ref="jobrepository" /> <property name="taskexecutor" ref="taskexecutor" /> </bean> <bean id="cvsitemreader" class="org.springframework.batch.item.file.flatfileitemreader"> <property name="resource" value="classpath:report.csv" /> <property name="linemapper"> <bean class="org.springframework.batch.item.file.mapping.defaultlinemapper"> <property name="linetokenizer"> <bean class="org.springframework.batch.item.file.transform.delimitedlinetokenizer"> <property name="names" value="id,sales,qty,staffname,date" /> </bean> </property> <property name="fieldsetmapper"> <bean class="org.springframework.batch.item.file.mapping.beanwrapperfieldsetmapper"> <property name="prototypebeanname" value="report" /> </bean> </property> </bean> </property> </bean> <bean id="xmlitemwriter" class="org.springframework.batch.item.xml.staxeventitemwriter"> <property name="resource" value="file:/home/username/report.xml" /> <property name="marshaller" ref="reportmarshaller" /> <property name="roottagname" value="report" /> </bean> <bean id="reportmarshaller" class="org.springframework.oxm.jaxb.jaxb2marshaller"> <property name="classestobebound"> <list> <value>report</value> </list> </property> </bean> <bean id="taskexecutor" class="org.springframework.core.task.simpleasynctaskexecutor" /> <bean id="transactionmanager" class="org.springframework.batch.support.transaction.resourcelesstransactionmanager" /> </beans>
report.java:
import javax.xml.bind.annotation.xmlattribute; import javax.xml.bind.annotation.xmlelement; import javax.xml.bind.annotation.xmlrootelement; @xmlrootelement(name = "record") public class report { private int id; private string sales; private int qty; private string staffname; private string date; @xmlattribute(name = "id") public int getid() { return id; } public void setid(int id) { this.id = id; } @xmlelement(name = "sales") public string getsales() { return sales; } public void setsales(string sales) { this.sales = sales; } @xmlelement(name = "qty") public int getqty() { return qty; } public void setqty(int qty) { this.qty = qty; } @xmlelement(name = "staffname") public string getstaffname() { return staffname; } public void setstaffname(string staffname) { this.staffname = staffname; } public string getdate() { return date; } public void setdate(string date) { this.date = date; } @override public string tostring() { return "report [id=" + id + ", sales=" + sales + ", qty=" + qty + ", staffname=" + staffname + "]"; } }
to run use servlet following code:
applicationcontext context = new classpathxmlapplicationcontext("job.xml"); joblauncher joblauncher = (joblauncher) context.getbean("joblauncher"); job job = (job) context.getbean("helloworldjob"); try { org.springframework.batch.core.jobexecution execution = joblauncher.run(job, new jobparameters()); system.out.println("exit status : " + execution.getstatus()); } catch (exception e) { e.printstacktrace(); }
Comments
Post a Comment