whatsnew.md 4.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
# 最新更新在 Spring 批 4.3 中

## 在 Spring 批 4.3 中最新更新

这个版本附带了许多新特性、性能改进、依赖更新和 API 修改。这一节描述了最重要的变化。有关更改的完整列表,请参阅[发行说明](https://github.com/spring-projects/spring-batch/releases/tag/4.3.0)

### 新功能

#### 新建同步 ItemStreamWriter

`SynchronizedItemStreamReader`类似,该版本引入了`SynchronizedItemStreamWriter`。这个特性在多线程的步骤中很有用,在这些步骤中,并发线程需要同步,以避免覆盖彼此的写操作。

#### 用于命名查询的新 JPaqueryProvider

这个版本在`JpaNativeQueryProvider`旁边引入了一个新的`JpaNamedQueryProvider`,以便在使用`JpaPagingItemReader`时简化 JPA 命名查询的配置:

```
JpaPagingItemReader<Foo> reader = new JpaPagingItemReaderBuilder<Foo>()
   .name("fooReader")
   .queryProvider(new JpaNamedQueryProvider("allFoos", Foo.class))
   // set other properties on the reader
   .build();
```

#### 新的 jpacursoritemreader 实现

JPA 2.2 增加了将结果作为游标而不是只进行分页的能力。该版本引入了一种新的 JPA 项读取器,该读取器使用此功能以类似于`JdbcCursorItemReader``HibernateCursorItemReader`的基于光标的方式流式传输结果。

#### 新 JobParametersIncrementer 实现

`RunIdIncrementer`类似,这个版本添加了一个新的`JobParametersIncrementer`,它基于 Spring 框架中的`DataFieldMaxValueIncrementer`

#### graalvm 支持

这个版本增加了在 GraalVM 上运行 Spring 批处理应用程序的初始支持。该支持仍处于实验阶段,并将在未来的版本中进行改进。

#### Java 记录支持

这个版本增加了在面向块的步骤中使用 Java 记录作为项的支持。新添加的`RecordFieldSetMapper`支持从平面文件到 Java 记录的数据映射,如以下示例所示:

```
@Bean
public FlatFileItemReader<Person> itemReader() {
	return new FlatFileItemReaderBuilder<Person>()
			.name("personReader")
			.resource(new FileSystemResource("persons.csv"))
			.delimited()
			.names("id", "name")
			.fieldSetMapper(new RecordFieldSetMapper<>(Person.class))
			.build();
}
```

在这个示例中,`Person`类型是一个 Java 记录,定义如下:

```
public record Person(int id, String name) { }
```

`FlatFileItemReader`使用新的`RecordFieldSetMapper`将来自`persons.csv`文件的数据映射到类型`Person`的记录。

### 性能改进

#### 在 RepositorYitemWriter 中使用批量写操作

直到版本 4.2,为了在`RepositoryItemWriter`中使用`CrudRepository#saveAll`,需要扩展 writer 并覆盖`write(List)`

在此版本中,`RepositoryItemWriter`已更新为默认使用`CrudRepository#saveAll`

#### 在 MongoitemWriter 中使用批量写操作

`MongoItemWriter`在 for 循环中使用`MongoOperations#save()`将项保存到数据库中。在此版本中,此 Writer 已更新为使用`org.springframework.data.mongodb.core.BulkOperations`

#### 作业启动/重启时间改进

`JobRepository#getStepExecutionCount()`的实现用于在内存中加载所有作业执行和步骤执行,以在框架端完成计数。在这个版本中,实现被更改为使用 SQL Count 查询对数据库执行一个单独的调用,以便计算执行的步骤。

### 依赖项更新

此版本将依赖 Spring 项目更新为以下版本:

* Spring 框架 5.3

* Spring 数据 2020.0

* Spring 集成 5.4

* Spring AMQP2.3

* Spring 为 Apache 卡夫卡 2.6

* 千分尺 1.5

### 异议

#### API 反对

以下是在此版本中已被弃用的 API 列表:

* `org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean`

* `org.springframework.batch.core.explore.support.MapJobExplorerFactoryBean`

* `org.springframework.batch.core.repository.dao.MapJobInstanceDao`

* `org.springframework.batch.core.repository.dao.MapJobExecutionDao`

* `org.springframework.batch.core.repository.dao.MapStepExecutionDao`

* `org.springframework.batch.core.repository.dao.MapExecutionContextDao`

* `org.springframework.batch.item.data.AbstractNeo4jItemReader`

* `org.springframework.batch.item.file.transform.Alignment`

* `org.springframework.batch.item.xml.StaxUtils`

* `org.springframework.batch.core.launch.support.ScheduledJobParametersFactory`

* `org.springframework.batch.item.file.MultiResourceItemReader#getCurrentResource()`

* `org.springframework.batch.core.JobExecution#stop()`

建议的替换可以在每个不推荐的 API 的 Javadoc 中找到。

#### SQLFire 支持弃用

自 2014 年 11 月 1 日起,SQLfire 一直位于[EOL](https://www.vmware.com/latam/products/pivotal-sqlfire.html)。这个版本取消了使用 SQLFire 作为作业存储库的支持,并计划在 5.0 版本中删除它。