在Spring Boot項目中,使用Spring Batch任務時,需要添加相應的依賴。以下是一個基本的Spring Boot Batch項目依賴設置示例:
pom.xml
文件中添加Spring Boot和Spring Batch的依賴:<dependencies>
<!-- Spring Boot Starter Web, including Spring MVC, Tomcat -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Spring Boot Starter Batch, including Spring Batch, Spring Data JPA, and an in-memory database -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch</artifactId>
</dependency>
<!-- Spring Boot Starter Data JPA, including Hibernate, Spring Data JPA, and a in-memory database -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- MySQL Connector -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!-- Spring Boot Starter Test, including testing utilities -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
application.properties
文件中配置Spring Batch和數據庫的相關屬性:# Spring Batch
spring.batch.job.names=myBatchJob
spring.batch.initial-size=10
spring.batch.max-pool-size=20
spring.batch.partition-count=5
# Database
spring.datasource.url=jdbc:mysql://localhost:3306/mydb?useSSL=false&serverTimezone=UTC
spring.datasource.username=myuser
spring.datasource.password=mypassword
spring.jpa.hibernate.ddl-auto=update
這個示例中,我們添加了Spring Boot Web、Spring Batch、Spring Data JPA和MySQL Connector的依賴,并在application.properties
文件中配置了Spring Batch和數據庫的相關屬性。