我开发了一个弹簧批处理,用于将用户加载到数据库中。我可以从eclipse运行它作为Java应用程序提供主类但不能通过unix服务器上的shell脚本运行批处理。我得到了这个例外:
org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'jobLauncher' is defined
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:529)
at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1095)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:277)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1093)
at com.batch.LoadBatch.launchJob(LoadBatch.java:56)
at com.batch.LoadBatch.main(LoadBatch.java:38)
我在job.xml文件中声明了我的bean,如下所示
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:batch="http://www.springframework.org/schema/batch"
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.1.xsd
http://www.springframework.org/schema/jdbc
http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd"">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>classpath:LoadBatch.properties </value>
</property>
</bean>
<bean id="jobRepository" class="org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean">
<property name="transactionManager" ref="transactionManager" />
</bean>
<bean id="transactionManager" class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
<bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
<property name="jobRepository" ref="jobRepository" />
</bean>
<!--
*****************************productLoadJob********************************
-->
<bean id="completionPolicy" class="org.springframework.batch.repeat.policy.DefaultResultCompletionPolicy"/>
<bean id="multiResourceReader"
class=" org.springframework.batch.item.file.MultiResourceItemReader" scope="step">
<property name="resources" value="file:///${inputFilePath}*.csv" />
<property name="delegate" ref="flatFileItemReader" />
</bean>
<bean id="flatFileItemReader" class="org.springframework.batch.item.file.FlatFileItemReader" scope="step">
<property name="lineMapper">
<bean class="org.springframework.batch.item.file.mapping.DefaultLineMapper">
<property name="fieldSetMapper">
<bean class="com.mapper.IndividualRetailerFieldSetMapper" />
</property>
<property name="lineTokenizer">
<bean class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
<property name="delimiter" value="," />
</bean>
</property>
</bean>
</property>
<property name="linesToSkip" value="1" />
</bean>
<bean id="flatFileItemWriter"
class="org.springframework.batch.item.file.FlatFileItemWriter" scope="step">
<property name="resource" value="file:${outputFilePath}${outputFileName}.${outputFileType}" />
<property name="appendAllowed" value="true" />
<property name="lineAggregator">
<bean class="org.springframework.batch.item.file.transform.DelimitedLineAggregator">
<property name="delimiter" value="," />
<property name="fieldExtractor">
<bean
class="org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor">
<property name="names" value="serialNo,mobileNo,role,parentId" />
</bean>
</property>
</bean>
</property>
</bean>
<bean id="itemProcessor" class="com.handlers.LoadWriter" scope="step">
<property name="LoadFileHandler" ref="filehandler" />
<property name="LoadFieldSetMapper" ref="LoadFieldSetMapper"/>
<property name="opId" value="ABC" />
<property name="buId" value="XYZ" />
</bean>
<bean id="batchExceptionListner" class="com.handlers.LoadBatchExceptionListener" >
<property name="irLoadFileHandler" ref="filehandler" />
</bean>
<bean id="filehandler" class="com.handlers.IRLoadFileHandler" />
<bean id="IRLoadFieldSetMapper" class="com.handlers.IRLoadFieldSetMapper" />
<bean id="skipExceptionListner" class="com.handlers.IRLoadSkipExceptionListener" />
<batch:job id="IRLoadJob">
<batch:step id="importFileStep">
<batch:tasklet>
<batch:chunk reader="multiResourceReader" writer="flatFileItemWriter"
processor="itemProcessor" commit-interval="1">
</batch:chunk>
</batch:tasklet>
</batch:step>
<batch:listeners>
<batch:listener ref="batchExceptionListner" />
</batch:listeners>
</batch:job>
</beans>
在此处添加上下文初始化代码:
context = new ClassPathXmlApplicationContext(new String[] {"classpath*:Job.xml"});
logger.info("context in Spring Initializer is :: " + context.getBeanDefinitionCount());
答案 0 :(得分:1)
我有两个位置的属性和xml文件,即我的批处理jar内部以及我配置批处理的服务器上的位置。我从jar内部删除了文件,我的批处理开始运行! :)