Appearance
二十、Spring Boot2.6新特性
1、默认禁止了循环依赖
循环依赖大家都知道,也被折磨过,这下 2.6.0 的版本默认禁止了循环依赖,如果程序中出现循环依赖就会报错。
当然并没有一锤子打死,也提供了开启允许循环依赖的配置,只需要在配置文件中开启即可:
yaml
spring:
main:
allow-circular-references: true
2、支持自定义脱敏规则
Spring Boot 现在可以清理/env
和 /configprops
端点中存在的敏感值。
自定义 SanitizingFunction 类型的 Bean 即可实现。
java
@Bean
public SanitizingFunction mobileSanitizingFunction() {
return data -> {
PropertySource<?> propertySource = data.getPropertySource();
if (propertySource.getName().contains("redis.properties")) {
if (data.getKey().equals("redis.mobile")) {
return data.withValue(SANITIZED_VALUE);
} }
return data;
};
}
3、Redis自动开启连接池
这个版本之前Redis连接池需要开发主动开启,但是这个版本默认是开启的。
如果需要关闭一样是提供了配置,如下:
jedis连接池关闭 :
properties
spring.redis.jedis.pool.enabled = false
lettuce连接池关闭 :
properties
spring.redis.lettuce.pool.enabled = false
4、响应式应用服务器会话属性
响应式应用服务器支持的会话属性已在此版本中扩展。
以前是在 spring.webflux.session下,现在在 server.reactive.session 下,并且提供与 servlet 版 本相同的属性。
5、Maven构建信息属性排除
现在可以从 Spring Boot Maven 或 Gradle 插件生成的 build-info.properties 文件中排除特定属性。
比如,排除 Maven 的 version 属性:
xml
<configuration>
<excludeInfoProperties>
<excludeInfoProperty>version</excludeInfoProperty>
</excludeInfoProperties>
</configuration>
6、支持使用WebTestClient来测试Spring MVC
开发人员可以使用 WebTestClient 在模拟环境中测试程序,只需要在Mock环境中使用
@AutoConfigureMockMvc注释,就可以轻松注入 WebTestClient。,省去编写测试程序。
7、支持 Log4j2 复合配置
现在支持 Log4j2 的复合配置,可以通过 logging.log4j2.config.override 参数来指定覆盖主日志配 置文件的其他日志配置文件。