Springbatch3.0.1的xml架构?

时间:2014-05-15 12:13:36

标签: spring-batch

我正在尝试在春季3.0.1中完成弹簧批处理,并且类路径中已包含足够的jar。当我尝试使用命令行作业运行程序运行项目时,我得到了一个由于spring3.0.1的miss match xml架构而显示的错误。我有3个不同的xml文件,如下所示

的applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?><?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
    xsi:schemalocation="  
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context-3.0.xsd  
    http://www.springframework.org/schema/mvc  
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <import resource="JobRepository.xml" />
</beans>

jobConfiguration.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:batch="http://www.springframework.org/schema/batch"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemalocation="  
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context-3.0.xsd  
    http://www.springframework.org/schema/mvc  
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <import resource="ApplicationContext.xml" />
    <bean abstract="true"
        class="org.springframework.batch.core.step.tasklet.TaskletStep" id="taskletStep">
        <property name="jobRepository" ref="jobRepository" />
        <property name="transactionManager" ref="transactionManager" />
    </bean>
    <bean class="com.mypackage.HelloWorldTasklet" id="helloTasklet">
        <property name="message" value="Hello World!" />
    </bean>
    <bean class="com.mypackage.HelloWorldTasklet" id="createdByTasklet">
        <property name="message" value="Created By Harish On Java" />
    </bean>
    <bean class="org.springframework.batch.core.job.SimpleJob" id="mySimpleJob">
        <property name="name" value="mySimpleJob" />
        <property name="steps">
            <list>
                <bean parent="taskletStep">
                    <property name="tasklet" ref="helloTasklet" />
                </bean>
                <bean parent="taskletStep">
                    <property name="tasklet" ref="createdByTasklet" />
                </bean>
            </list>
        </property>
        <property name="jobRepository" ref="jobRepository" />
    </bean>
</beans>

JobRepository.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:batch="http://www.springframework.org/schema/batch"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans"
    xsi:schemalocation="  
    http://www.springframework.org/schema/beans  
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  
    http://www.springframework.org/schema/context  
    http://www.springframework.org/schema/context/spring-context-3.0.xsd  
    http://www.springframework.org/schema/mvc  
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
    <bean
        class="org.springframework.batch.core.repository.support.SimpleJobRepository"
        id="jobRepository">
        <constructor-arg>
            <bean
                class="org.springframework.batch.core.repository.dao.MapJobInstanceDao" />
        </constructor-arg>
        <constructor-arg>
            <bean
                class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
        </constructor-arg>
        <constructor-arg>
            <bean
                class="org.springframework.batch.core.repository.dao.MapStepExecutionDao" />
        </constructor-arg>
        <constructor-arg>
            <bean
                class="org.springframework.batch.core.repository.dao.MapExecutionContextDao" />
        </constructor-arg>
    </bean>
    <bean id="transactionManager"
        class="org.springframework.batch.support.transaction.ResourcelessTransactionManager" />
    <bean class="org.springframework.batch.core.launch.support.SimpleJobLauncher"
        id="jobLauncher">
        <property name="jobRepository" ref="jobRepository" />
    </bean>
</beans>

Java代码:

public class HelloWorldTasklet implements Tasklet {
    private String message;

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public RepeatStatus execute(StepContribution contribution,
            ChunkContext context) throws Exception {
        // TODO Auto-generated method stub
        System.out.println(message);
        return RepeatStatus.FINISHED;
    }
}

我的lib包含以下jars

com.springsource.org.aopalliance-1.0.0.jar
com.springsource.org.apache.commons.lang-sources-2.1.0.jar
com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.log4j-1.2.15.jar
commons-beanutils-1.8.3.jar
commons-codec-1.3.jar
commons-collections-3.2.jar 
commons-digester-1.8.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
org.springframework.aop-3.0.1.RELEASE-A.jar
org.springframework.asm-3.0.1.RELEASE-A.jar
org.springframework.aspects-3.0.1.RELEASE-A.jar
org.springframework.beans-3.0.1.RELEASE-A.jar
org.springframework.context-3.0.1.RELEASE-A.jar
org.springframework.context.support-3.0.1.RELEASE-A.jar
org.springframework.core-3.0.1.RELEASE-A.jar
org.springframework.expression-3.0.1.RELEASE-A.jar
org.springframework.web-3.0.1.RELEASE-A.jar
org.springframework.web.servlet-3.0.1.RELEASE-A.jar
spring-batch-core-2.2.0.RELEASE.jar
spring-batch-infrastructure-2.2.0.RELEASE.jar

任何回复都会提前得到很高的评价。

1 个答案:

答案 0 :(得分:0)

您的类路径上有Spring Batch 2.2.0.RELEASE jar,但您没有在模式中指定该版本。更新以使用版本,你会没事的。

作为旁注,您是否有理由不在配置中使用模式?在配置批处理组件时,如果不使用命名空间或工厂bean,就会很难实现。例如,而不是:

<bean
    class="org.springframework.batch.core.repository.support.SimpleJobRepository"
    id="jobRepository">
    <constructor-arg>
        <bean
            class="org.springframework.batch.core.repository.dao.MapJobInstanceDao" />
    </constructor-arg>
    <constructor-arg>
        <bean
            class="org.springframework.batch.core.repository.dao.MapJobExecutionDao" />
    </constructor-arg>
    <constructor-arg>
        <bean
            class="org.springframework.batch.core.repository.dao.MapStepExecutionDao" />
    </constructor-arg>
    <constructor-arg>
        <bean
            class="org.springframework.batch.core.repository.dao.MapExecutionContextDao" />
    </constructor-arg>
</bean>

你可以这样做:

<bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="transactionManager" ref="transactionManager"/>
</bean>

我们还为作业配置提供名称空间支持。而不是:

<bean class="org.springframework.batch.core.job.SimpleJob" id="mySimpleJob">
    <property name="name" value="mySimpleJob" />
    <property name="steps">
        <list>
            <bean parent="taskletStep">
                <property name="tasklet" ref="helloTasklet" />
            </bean>
            <bean parent="taskletStep">
                <property name="tasklet" ref="createdByTasklet" />
            </bean>
        </list>
    </property>
    <property name="jobRepository" ref="jobRepository" />
</bean>

你应该试试这个:

<batch:job id="mySimpleJob">
    <batch:step id="step1" next="step2">
        <batch:tasklet ref="helloTasklet"/>
    </batch:step>
    <batch:step id="step2">
        <batch:tasklet ref="createdByTasklet"/>
    </batch:step>
</batch:job>

命名空间处理一些细节,例如自动连接作业存储库和事务管理器等。我建议您在这里查看Spring Batch文档:http://docs.spring.io/spring-batch/2.2.x/reference/html/index.html