2015-10-02 32 views
-2
错误

你好下面是我创建asynchlob发射 春天批次AsynchJob启动,在设置作业回购

<bean id="jobLauncher" 
    class="org.springframework.batch.core.launch.support.SimpleJobLauncher"> 
    <property name="jobRepository" ref="&amp;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" /> 

我收到以下错误

Error creating bean with name 'batchJobLauncher': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.batch.core.launch.support.SimpleJobLauncher com.batch.launcher.BatchJobLauncher.asyncJobLauncher; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jobLauncher' defined in ServletContext resource [/WEB-INF/BatchConfig.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean' to required type 'org.springframework.batch.core.repository.JobRepository' for property 'jobRepository'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean] to required type [org.springframework.batch.core.repository.JobRepository] for property 'jobRepository': no matching editors or conversion strategy found 
..... 
caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean' to required type 'org.springframework.batch.core.repository.JobRepository' for property 'jobRepository'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean] to required type [org.springframework.batch.core.repository.JobRepository] for property 'jobRepository': no matching editors or conversion strategy found 
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:476) [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE] 
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:512) [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE] 
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:506) [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1523) [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1482) [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1222) [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE] 
at 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] to required type [org.springframework.batch.core.repository.JobRepository] for property 'jobRepository': no matching editors or conversion strategy found 
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:287) [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE] 
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:461) [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE] 
... 60 more 

我尝试没有&也正在配置。

误差这样

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 with name 'jobBuilders' defined in class path resource [org/springframework/batch/core/configuration/annotation/SimpleBatchConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.batch.core.configuration.annotation.JobBuilderFactory]: Factory method 'jobBuilders' threw exception; nested exception is java.lang.ClassCastException: org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean$$EnhancerBySpringCGLIB$$99e29281 cannot be cast to org.springframework.batch.core.repository.JobRepository 
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) [spring-beans-4.1.6.RELEASE.jar:4.1.6.RELEASE] 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1119) 
+1

请注意,标签[标签:批处理文件]是'Windows'相关;所以我改编了标签... – aschipfl

回答

1

下面是从http://www.mkyong.com/spring-batch/spring-batch-hello-world-example/制成和测试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 + "]"; 
    } 

} 

要运行中使用的servlet用下面的代码:

 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(); 
} 
+0

谢谢。从应用程序上下文看来,我正确地获得了启动器。看来自动布线是导致该错误的原因。我在启动器上删除了它的自动装配。 – user3735766