Spring Batch 简明教程

Spring Batch - Environment

在本章中,我们将解释如何将 Spring Batch 环境设置到 Eclipse IDE 中。在继续安装前,确保您已在您的系统中安装 Eclipse。如果没有,请在您的系统中下载并安装 Eclipse。

如需了解 Eclipse 的更多信息,请参考我们的 Eclipse Tutorial.

Setting Spring Batch on Eclipse

按照以下步骤在 Eclipse 上设置 Spring Batch 环境。

Step 1 − 安装 Eclipse,然后打开一个新项目,如以下屏幕截图所示。

new project

Step 2 − 创建一个样本 Spring Batch 项目,如下所示。

project name

Step 3 − 右键单击项目,然后按以下所示将其转换为一个 Maven 项目。将其转换为 Maven 项目后,将提供 Pom.xml ,您需要在其中提及必需的依赖项。然后,将 jar 文件自动下载到您的项目中。

configure

Step 4 − 现在,在项目的 pom.xml 中,复制并粘贴以下内容(spring 批处理应用程序的依赖项),然后刷新项目。

<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>com.tutorialspoint</groupId>
   <artifactId>SpringBatchSample</artifactId>
   <packaging>jar</packaging>
   <version>1.0-SNAPSHOT</version>
   <name>SpringBatchExample</name>
   <url>http://maven.apache.org</url>

   <properties>
      <jdk.version>1.8</jdk.version>
      <spring.version>5.3.14</spring.version>
      <spring.batch.version>4.3.4</spring.batch.version>
      <mysql.driver.version>5.1.25</mysql.driver.version>
      <junit.version>4.11</junit.version>
   </properties>

   <dependencies>
      <!-- Spring Core -->
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-core</artifactId>
         <version>${spring.version}</version>
      </dependency>

      <!-- Spring jdbc, for database -->
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-jdbc</artifactId>
         <version>${spring.version}</version>
      </dependency>

      <!-- Spring XML to/back object -->
      <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-oxm</artifactId>
         <version>${spring.version}</version>
      </dependency>

      <!-- MySQL database driver -->
      <dependency>
         <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
         <version>${mysql.driver.version}</version>
      </dependency>

      <!-- Spring Batch dependencies -->
      <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>

      <!-- Spring Batch unit test -->
      <dependency>
         <groupId>org.springframework.batch</groupId>
         <artifactId>spring-batch-test</artifactId>
         <version>${spring.batch.version}</version>
      </dependency>

      <!-- Junit -->
      <dependency>
         <groupId>junit</groupId>
         <artifactId>junit</artifactId>
         <version>${junit.version}</version>
         <scope>test</scope>
      </dependency>
   </dependencies>

   <build>
      <finalName>spring-batch</finalName>
      <plugins>
         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.9</version>
            <configuration>
               <downloadSources>true</downloadSources>
               <downloadJavadocs>false</downloadJavadocs>
            </configuration>
         </plugin>

         <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
               <source>${jdk.version}</source>
               <target>${jdk.version}</target>
            </configuration>
         </plugin>
      </plugins>
   </build>
</project>