paulwong

SRING INTEGRATION + BATCH

场景:由SPRING INTEGRATION每10秒监控数据库中的POLL表,如果有符合条件的记录,则启动JDBC JOB,此JOB要做的也是和数据库交互的动作,如用JDBCITEMREADER读取数据库记录,用JDBCITEMWRITER写记录进数据库 。


SPRING INTEGRATION与SPRING BATCH JOB交互的点是JOBPARAMETERS,即以KEY-VALU的形式放东西进去,这样BATCH JOB就能读到。


SPRING INTEGRATION要启动哪个JOB,是在JOBCHANNEL的消费者中设定的,且只能设定一个JOB。


SPRING INTEGRATION中监控数据库的是一个ADAPTER,hello-integration-jdbc-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans
="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:jdbc
="http://www.springframework.org/schema/integration/jdbc"
    xsi:schemaLocation
="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
        http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd"
>

    <!-- 此CHANNEL中放的是一个MEASSAGE,主体是SELECT出来的RESULT LIST<Map<String Object>> -->
    <channel id="jdbcChannel"/>

    <jdbc:inbound-channel-adapter channel="jdbcChannel"
        data-source
="dataSource" 
        query
="SELECT * FROM T_POOL T WHERE T.POOL = 0"
        update
="UPDATE T_POOL T set T.POOL=1 where T.id in (:ID)"
        
>
        <poller max-messages-per-poll="1" cron="0/1 * * * * *" >
            <!-- 这里如果要下一个CHANNEL也在一个TRANSACTION中,则加,但加了后REPOSITORY中报错 -->
            <!-- <transactional transaction-manager="appTransactionManager"/> -->
        </poller>
    </jdbc:inbound-channel-adapter>
    
    <!--update="UPDATE T_USER T set T.polled=1 where T.id in (:ID)"-->
    
    <service-activator input-channel="jdbcChannel"
                       output-channel
="jobLaunchRequestChannel"
                       ref
="jdbcToJobLaunchRequestAdapter"/>
                       
    <beans:bean id="jdbcToJobLaunchRequestAdapter" class="com.paul.integration.jdbc.JDBCToJobLaunchRequestAdapter">
        <beans:property name="job" ref="jdbcJob"/>
    </beans:bean>
    
    <beans:bean id="appDataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <beans:property name="driverClassName" value="${batch.jdbc.driver}" />
        <beans:property name="url" value="${batch.jdbc.url}" />
        <beans:property name="username" value="${batch.jdbc.user}" />
        <beans:property name="password" value="${batch.jdbc.password}" />
    </beans:bean>

    <beans:bean id="appTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" lazy-init="true">
        <beans:property name="dataSource" ref="appDataSource" />
    </beans:bean>

</beans:beans>


INTEGRATION主体文件,hello-integration-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:beans
="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:file
="http://www.springframework.org/schema/integration/file"
    xsi:schemaLocation
="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
        http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd"
>

    <beans:import resource="integration/hello-integration-jdbc-context.xml"/>

    <channel id="jobExecutionChannel"/>
    <channel id="jobLaunchRequestChannel"/>
    <logging-channel-adapter channel="jobExecutionChannel" />

    <service-activator input-channel="jobLaunchRequestChannel" output-channel="jobExecutionChannel">
        <beans:bean class="org.springframework.batch.integration.launch.JobLaunchingMessageHandler">
            <beans:constructor-arg ref="jobLauncher" />
        </beans:bean>
    </service-activator>

</beans:beans>


JDBC CHANNEL的消费者,JDBCToJobLaunchRequestAdapter:
package com.paul.integration.jdbc;

import java.io.File;
import java.util.List;
import java.util.Map;

import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.launch.NoSuchJobException;
import org.springframework.batch.integration.launch.JobLaunchRequest;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.util.Assert;

/**
 * Adapt a {
@link File} to a {@link JobLaunchRequest} with a job parameter
 * <code>input.file</code> equal to the path of the file.
 * 
 * 
@author Dave Syer
 * 
 
*/
@MessageEndpoint
public class JDBCToJobLaunchRequestAdapter implements InitializingBean {

    private Job job;

    public void setJob(Job job) {
        this.job = job;
    }

    public void afterPropertiesSet() throws Exception {
        Assert.notNull(job, "A Job must be provided");
    }
    
    @ServiceActivator
    //此处如要丢东西到下一CHANNEL,则要设返回对象
    public JobLaunchRequest handleJdbcMessage(List<Map<String, Object>> message) {
        for (Map<String, Object> resultMap : message) {
            System.out.println("Row");
            for (String column : resultMap.keySet()) {
                System.out.println("column: " + column + " value: "
                        + resultMap.get(column));
            }
        }
        
        JobParameters jobParameters = new JobParametersBuilder().
                addString("id", "1").
                addLong("time.stamp", System.currentTimeMillis()).
                toJobParameters();

        if (job.getJobParametersIncrementer() != null) {
            jobParameters = job.getJobParametersIncrementer().getNext(jobParameters);
        }

        return new JobLaunchRequest(job, jobParameters);
    }

}


JDBC JOB,jdbc-job-context.xml:
<?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:batch
="http://www.springframework.org/schema/batch"
    xmlns:util
="http://www.springframework.org/schema/util"
    xsi:schemaLocation
="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
        http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd"
>

    

    <batch:job id="jdbcJob">
        <batch:step id="step1" next="jdbcReadAndWriterStep">
            <batch:tasklet ref="helloWorldTasklet"></batch:tasklet>
        </batch:step>
         <batch:step id="jdbcReadAndWriterStep">
             <batch:tasklet>
                 <batch:chunk reader="jdbcItemReader" writer="jdbcItemWriter" processor="jdbcProcessor"
                     commit-interval
="10">
                 </batch:chunk>
             </batch:tasklet>
         </batch:step>
    </batch:job>
    
    <bean id="helloWorldTasklet" class="com.paul.batch.tasklet.HelloWorldTasklet"></bean>
    
    
    <bean id="jdbcItemReader"
         class
="org.springframework.batch.item.database.JdbcCursorItemReader"
         scope
="step">
         <property name="dataSource" ref="dataSource" />
         <property name="sql"
             value
="select id,userId,userName,password from T_USER where id = ?" />
         <property name="rowMapper">
             <bean class="org.springframework.jdbc.core.BeanPropertyRowMapper">
                 <property name="mappedClass"
                     value
="com.paul.domain.User" />
             </bean>
         </property>
         <property name="preparedStatementSetter" ref="paramStatementSetter" />
     </bean>
 
     <bean id="paramStatementSetter"
         class
="org.springframework.batch.core.resource.ListPreparedStatementSetter"
         scope
="step">
         <property name="parameters">
             <list>
                 <value>#{jobParameters['id']}</value>
             </list>
         </property>
     </bean>
     
    <bean id="jdbcProcessor" class="com.paul.batch.JDBCProcessor" />

    <bean id="jdbcItemWriter"
        class
="org.springframework.batch.item.database.JdbcBatchItemWriter">
        <property name="dataSource" ref="dataSource" />
        <property name="sql"
            value
="insert into T_DESTUSER (USERID,USERNAME,PASSWORD,UPDATETIME,UPDATEUSER)
                    values
                   (:userId,:userName,:password,:updateTime,:updateUser)"
 />
        <property name="itemSqlParameterSourceProvider">
            <bean class="org.springframework.batch.item.database.BeanPropertyItemSqlParameterSourceProvider" />
        </property>
    </bean>
    
</beans>


SPRING BATCH的主体对象配置文件,launch-context.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:p
="http://www.springframework.org/schema/p" 
    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.1.xsd
        http://www.springframework.org/schema/beans 
           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd"
>

    <!-- <import resource="classpath:/META-INF/spring/module-context.xml"/> -->

    <bean id="jobOperator"
        class
="org.springframework.batch.core.launch.support.SimpleJobOperator"
        p:jobLauncher-ref
="jobLauncher" p:jobExplorer-ref="jobExplorer"
        p:jobRepository-ref
="jobRepository" p:jobRegistry-ref="jobRegistry" />

    <bean id="jobExplorer"
        class
="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"
        p:dataSource-ref
="dataSource" />

    <bean id="jobRegistry"
        class
="org.springframework.batch.core.configuration.support.MapJobRegistry" />
        
    <bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
        <property name="jobRegistry" ref="jobRegistry"/>
    </bean>
    
    <bean id="jobLauncher"
        class
="org.springframework.batch.core.launch.support.SimpleJobLauncher">
        <property name="jobRepository" ref="jobRepository" />
    </bean>
    
    <batch:job-repository id="jobRepository"
        data-source
="dataSource"
        transaction-manager
="transactionManager"
        isolation-level-for-create
="READ_COMMITTED"
        max-varchar-length
="3000"
    
/>
    
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${batch.jdbc.driver}" />
        <property name="url" value="${batch.jdbc.url}" />
        <property name="username" value="${batch.jdbc.user}" />
        <property name="password" value="${batch.jdbc.password}" />
    </bean>

    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager" lazy-init="true">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <bean id="placeholderProperties" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:batch.properties" />
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
        <property name="ignoreUnresolvablePlaceholders" value="true" />
        <property name="order" value="1" />
    </bean>

    <!-- Initialize the datasource - remove this bean definition for production use! -->
    <!-- <bean id="dataSourceInitializer" class="test.jdbc.datasource.DataSourceInitializer">
        <property name="dataSource" ref="dataSource"/>
        <property name="initScripts" value="${batch.schema.script}"/>
    </bean> 
-->

</beans>


BATCH STEP中的DOMAIN对象,User:
package com.paul.domain;

import java.util.Date;

public class User {
    
    private int id;
    private int userId;
    private String userName;
    private String password;
    private Date updateTime;
    private int updateUser;
    
    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public int getUserId() {
        return userId;
    }
    public void setUserId(int userId) {
        this.userId = userId;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    public Date getUpdateTime() {
        return updateTime;
    }
    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
    public int getUpdateUser() {
        return updateUser;
    }
    public void setUpdateUser(int updateUser) {
        this.updateUser = updateUser;
    }

}


测试文件,HelloTaskletTests.java:
/*
 * Copyright 2006-2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      
http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 
*/
package example;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.BatchStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@ContextConfiguration(locations = { "/test-context.xml",
        "classpath:/META-INF/spring/hello-tasklet-context.xml",
        "classpath:/META-INF/spring/jdbc-job-context.xml",
        "classpath:/META-INF/spring/hello-integration-context.xml"})
@RunWith(SpringJUnit4ClassRunner.class)
public class HelloTaskletTests {
    
    @Autowired
    private JobLauncher jobLauncher;
    
    @Autowired
    private Job helloWorldJob;

    @Autowired
    private JobLauncherTestUtils jobLauncherTestUtils;
    
    public void testLaunchJobWithJobLauncher() throws Exception {
        JobExecution jobExecution = jobLauncher.run(helloWorldJob, new JobParameters());
        assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
    }

    /**
     * Create a unique job instance and check it's execution completes
     * successfully - uses the convenience methods provided by the testing
     * superclass.
     
*/
    public void testLaunchJob() throws Exception {

        JobExecution jobExecution = jobLauncherTestUtils.launchJob(jobLauncherTestUtils.getUniqueJobParameters());
        assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
    }
    
    @Test
    public void testIntegration()
    {
        while(true)
        {
            
        }
    }


}


测试用的配置文件,:
<?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"
    xsi:schemaLocation
="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd"
>

    <import resource="classpath*:/launch-context.xml"/>
    
    <context:annotation-config/>
    
    <bean class="org.springframework.batch.test.JobLauncherTestUtils">
        <property name="job" ref="helloWorldJob" />
    </bean>

</beans>


MAVEN POM:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.springframework.batch</groupId>
    <artifactId>spring-batch-simple-cli</artifactId>
    <version>2.1.9.RELEASE</version>
    <packaging>jar</packaging>
    <name>Commandline</name>
    <url>http://www.springframework.org/spring-batch/archetypes/simple-cli-archetype</url>
    <description>This project is a minimal command line batch sample from
        Spring Batch. Once installed you can use "mvn exec:java" to
        see the job run; or if you ship the lib directory you can put
        the project jar on the classpath and run the
        CommandLineJobRunner directly or with "java -jar launch-context.xml job1".</description>
    <properties>
        <maven.test.failure.ignore>true</maven.test.failure.ignore>
        <spring.framework.version>3.0.5.RELEASE</spring.framework.version>
        <spring.batch.version>2.1.9.RELEASE</spring.batch.version>
        <dependency.locations.enabled>false</dependency.locations.enabled>
        <spring.integration.version>2.0.6.RELEASE</spring.integration.version>
    </properties>
    <profiles>
        <profile>
            <id>strict</id>
            <properties>
                <maven.test.failure.ignore>false</maven.test.failure.ignore>
            </properties>
        </profile>
        <profile>
            <id>staging</id>
            <distributionManagement>
                <repository>
                    <id>staging</id>
                    <url>file:///${user.dir}/target/staging</url>
                </repository>
                <snapshotRepository>
                    <id>staging</id>
                    <url>file:///${user.dir}/target/staging</url>
                </snapshotRepository>
            </distributionManagement>
        </profile>
        <profile>
            <id>bootstrap</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <pluginRepositories>
                <!-- <pluginRepository>
                    <id>Codehaus</id>
                    <url>http://repository.codehaus.org/</url>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository> 
-->
                <pluginRepository>
                    <id>com.springsource.repository.bundles.release</id>
                    <name> SpringSource Enterprise Bundle Repository - SpringSource Bundle Releases</name>
                    <url>http://repository.springsource.com/maven/bundles/release</url>
                    <snapshots>
                        <enabled>false</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${spring.framework.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.framework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${spring.framework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>${spring.framework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-core</artifactId>
            <version>${spring.batch.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-infrastructure</artifactId>
            <version>${spring.batch.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-test</artifactId>
            <version>${spring.batch.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.5.8</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.14</version>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>hsqldb</groupId>
            <artifactId>hsqldb</artifactId>
            <version>1.8.0.7</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjrt</artifactId>
            <version>1.5.4</version>
        </dependency>
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>1.5.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-core</artifactId>
            <version>${spring.integration.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.batch</groupId>
            <artifactId>spring-batch-integration</artifactId>
            <version>1.2.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-file</artifactId>
            <version>${spring.integration.version}</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.21</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-oxm</artifactId>
            <version>${spring.framework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.integration</groupId>
            <artifactId>spring-integration-jdbc</artifactId>
            <version>${spring.integration.version}</version>
        </dependency>
    </dependencies>
    <build>
        <extensions>
            <extension>
                <groupId>org.springframework.build.aws</groupId>
                <artifactId>org.springframework.build.aws.maven</artifactId>
                <version>3.0.0.RELEASE</version>
            </extension>
        </extensions>
        <pluginManagement>
            <plugins>
                <plugin>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <inherited>false</inherited>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>project</descriptorRef>
                        </descriptorRefs>
                    </configuration>
                </plugin>
                <!--This plugin's configuration is used to store Eclipse m2e settings 
                    only. It has no influence on the Maven build itself. 
-->
                <plugin>
                    <groupId>org.eclipse.m2e</groupId>
                    <artifactId>lifecycle-mapping</artifactId>
                    <version>1.0.0</version>
                    <configuration>
                        <lifecycleMappingMetadata>
                            <pluginExecutions>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>com.springsource.bundlor</groupId>
                                        <artifactId>com.springsource.bundlor.maven</artifactId>
                                        <versionRange>[1.0,)</versionRange>
                                        <goals>
                                            <goal>bundlor</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore />
                                    </action>
                                </pluginExecution>
                                <pluginExecution>
                                    <pluginExecutionFilter>
                                        <groupId>org.apache.maven.plugins</groupId>
                                        <artifactId>maven-dependency-plugin</artifactId>
                                        <versionRange>[1.0,)</versionRange>
                                        <goals>
                                            <goal>copy-dependencies</goal>
                                        </goals>
                                    </pluginExecutionFilter>
                                    <action>
                                        <ignore />
                                    </action>
                                </pluginExecution>
                            </pluginExecutions>
                        </lifecycleMappingMetadata>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.springsource.bundlor</groupId>
                <artifactId>com.springsource.bundlor.maven</artifactId>
                <version>1.0.0.RELEASE</version>
                <executions>
                    <execution>
                        <id>bundlor-transform</id>
                        <phase>compile</phase>
                        <goals>
                            <goal>bundlor</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.3</version>
                <configuration>
                    <includes>
                        <include>**/*Tests.java</include>
                    </includes>
                    <excludes>
                        <exclude>**/Abstract*.java</exclude>
                    </excludes>
                    <junitArtifactName>junit:junit</junitArtifactName>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>exec-maven-plugin</artifactId>
                <version>1.1</version>
                <configuration>
                    <mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass>
                    <arguments>
                        <argument>classpath:/launch-context.xml</argument>
                        <argument>job1</argument>
                    </arguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3</version>
                <configuration>
                    <archive>
                        <index>false</index>
                        <manifest>
                            <mainClass>org.springframework.batch.core.launch.support.CommandLineJobRunner</mainClass>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                        <manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <distributionManagement>
        <downloadUrl>http://www.springframework.org/download</downloadUrl>
        <site>
            <id>staging</id>
            <url>file:///${user.dir}/target/staging/org.springframework.batch.archetype/${pom.artifactId}</url>
        </site>
        <repository>
            <id>spring-release</id>
            <name>Spring Release Repository</name>
            <url>file:///${user.dir}/target/staging/release</url>
        </repository>
        <snapshotRepository>
            <id>spring-snapshot</id>
            <name>Spring Snapshot Repository</name>
            <url>file:///${user.dir}/target/staging/snapshot</url>
        </snapshotRepository>
    </distributionManagement>
</project>


属性配置文件,batch.properties:
# Placeholders batch.*
#    for MySQL:
batch.jdbc.driver=com.mysql.jdbc.Driver
batch.jdbc.url=jdbc:mysql://localhost/spring_batch
batch.jdbc.user=root
batch.jdbc.password=12345
batch.jdbc.testWhileIdle=true
batch.jdbc.validationQuery=SELECT 1
batch.schema.script=classpath:/org/springframework/batch/core/schema-mysql.sql
batch.drop.script=classpath*:/org/springframework/batch/core/schema-drop-mysql.sql
batch.business.schema.script=classpath:/business-schema-mysql.sql
batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer

# Non-platform dependent settings that you might like to change
# batch.data.source.init=true


posted on 2012-10-21 17:23 paulwong 阅读(911) 评论(0)  编辑  收藏 所属分类: SPRING INTERGRATIONSRPING BATCH


只有注册用户登录后才能发表评论。


网站导航: