Hello,
I have tried to trigger the execution of the BatchCommandLineLauncher for restartSample through a servlet. For this purpose, I have made following changes in BatchCommandLineLauncher :
• Created Default constructor
Code:/**In BatchCommandLineLauncher code*******/ //appended below lines. //class level variable or Class Member. private String beanRefContextPath=null; private String parentKey=null; /** * When you create the object of BatchCommandLineLauncher,the * values for beanRefContextPath and parentKey are initialised. */ public BatchCommandLineLauncher() { beanRefContextPath = System.getProperty(BEAN_REF_CONTEXT_KEY, DEFAULT_BEAN_REF_CONTEXT_PATH); parentKey= System.getProperty(BATCH_EXECUTION_ENVIRONMENT_KEY, DEFAULT_PARENT_KEY); beanFactoryLocator = ContextSingletonBeanFactoryLocator .getInstance(beanRefContextPath); }
• Changed the signature of the start function to :
/**
* No need to provided parentKey parameter as it is * initialised to the required value while creating the * object : command
*/
/**In BatchCommandLineLauncher code*******/
int start(String path, String jobName)
On Client side, I have designed a HTML page with a button. On Click of that button, I have call the servlet. The servlet has following service function :
Code:protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { try { PrintWriter pw=res.getWriter(); pw.println("Calling BatchCommandLineLauncher default constructor i.e. with " + "no parameter"); /** * When you create the object of BatchCommandLineLauncher, the values for * beanRefContextPath and parentKey are initialised. */ BatchCommandLineLauncher command = new BatchCommandLineLauncher(); pw.println("Calling start method of the BatchCommandLineLauncher with parameter :path and jobName"); /** * No need to provided parentKey parameter as it is initialised to the required * value while creating the object : command */ int result = command.start("restartSample.xml", "restartSampleJob"); pw.println("After start is called."); } catch (Exception e) { e.printStackTrace(); } }
But on the click on the button , I encountered an exception on Tomcat console stated :
According to my observation, the ConfigurableApplicationContext in start() function is working properly.The exeception is raise at this line :Code:09:53:09,068 FATAL BatchCommandLineLauncher:276 - org.springframework.beans.fact ory.BeanCreationException: Error creating bean with name 'restartSampleJob' defi ned in class path resource [restartSample.xml]: Cannot create inner bean 'step1' of type [org.springframework.batch.execution.step.SimpleStepConfiguration] whil e setting bean property 'steps'; nested exception is org.springframework.beans.f actory.BeanCreationException: Error creating bean with name 'step1' defined in c lass path resource [restartSample.xml]: Cannot create inner bean 'ExceptionResta rtableTasklet#fdb413' of type [ExceptionRestartableTasklet] while setting bean p roperty 'tasklet'; nested exception is org.springframework.beans.factory.BeanCre ationException: Error creating bean with name 'ExceptionRestartableTasklet#fdb41 3' defined in class path resource [restartSample.xml]: Cannot create inner bean 'org.springframework.batch.item.provider.ValidatingItemProvider#4b3f8b' of type [org.springframework.batch.item.provider.ValidatingItemProvider] while setting b ean property 'itemProvider'; nested exception is org.springframework.beans.facto ry.BeanCreationException: Error creating bean with name 'org.springframework.bat ch.item.provider.ValidatingItemProvider#4b3f8b' defined in class path resource [ restartSample.xml]: Cannot resolve reference to bean 'fileInputSource' while set ting bean property 'inputSource'; nested exception is org.springframework.beans. factory.BeanCreationException: Error creating bean with name 'fileInputSource': Initialization of bean failed; nested exception is java.lang.ExceptionInInitiali zerError
context = new ClassPathXmlApplicationContext(new String[] {path},parent);
Just for clarification : The values for path and parent which are supplied to above function are proper. I have checked the values by printing method on console.
If someone can help me.
Thanks in advance.


Reply With Quote
