网站首页 > 文章精选 正文
推荐阅读:
Spring Framework升级
SpringBoot2.2的底层Spring Framework版本升级为5.2。
JMX默认禁用
默认情况下不再启用JMX。 可以使用配置属性spring.jmx.enabled = true启用此功能。 如果您使用IDE功能来管理应用程序,则可能还要在该位置启用该标志。
Java 13支持
Spring Boot 2.2增加了对Java 13的支持。还支持Java 8和11。
性能提升
通过使用proxyBeanMethods=falseSpring Boot的@Configuration类,减少了启动时间和内存使用量。 proxyBeanMethods是@ConfigurationSpring Framework 5.2 M1中引入的新属性。 proxyBeanMethods也可作为一个属性@SpringBootApplication和@SpringBootConfiguration。
在使用bootRunGradle或spring-boot:runMaven 在开发时启动应用程序时,JVM将配置有标志(-Xverify:none和-XX:TieredStopAtLevel=1)以对其进行优化以减少启动时间。在JDK 13上运行时,-Xverify:none未指定,因为已弃用。
此版本中还进行了其他一些性能改进:
- 绑定大量配置属性所需的时间已大大减少
- 当Spring Boot PersistenceUnit通过扫描JPA实体完全准备一个时,由于它是冗余的,因此Hibernate自己的实体扫描已被禁用
- 自动配置中的注入点已经过改进,仅适用于必须创建bean的情况
- 现在仅在启用和公开端点的情况下(通过JMX或HTTP)创建与Actuator端点相关的Bean。
- 编解码器自动配置的条件已得到改善,以便在不再使用编解码器时不再对其进行配置
- Tomcat的MBean注册表默认情况下处于禁用状态,从而将Tomcat的内存占用量减少了大约2MB
延迟初始化
现在可以通过该
spring.main.lazy-initialization属性启用全局延迟初始化以减少启动时间。请注意,使用该功能需要付费:
- 在进行任何延迟的初始化时,HTTP请求的处理可能需要更长的时间
- 现在,通常不会在启动时发生故障,直到以后
通过使用注释各自的定义,各个bean可以选择退出延迟初始化@Lazy(false)。如果无法@Lazy(false)选择退出延迟初始化,
LazyInitializationExcludeFilter则可以使用Bean代替。例如,要永远不要将IntegrationFlowbean 设置为惰性,可以使用以下代码:
@Bean static LazyInitializationExcludeFilter integrationLazyInitExcludeFilter() { return LazyInitializationExcludeFilter.forBeanTypes(IntegrationFlow.class); }
JUnit 5
spring-boot-starter-test现在默认提供JUnit 5。默认情况下,包括JUnit 5的老式引擎以支持现有的基于JUnit 4的测试类,以便您可以在准备好迁移到JUnit 5时进行迁移。也可以在同一模块中混合使用基于JUnit 4和基于JUnit 5的测试类。这使您可以根据需要逐步迁移到JUnit 5。
请注意,JUnit 4的Maven Surefire插件不支持该listener属性。如果您具有类似于以下内容的Maven配置:
<configuration> <properties> <property> <name>listener</name> <value>com.example.CustomRunListener</value> </property> </properties> </configuration>
不能使用,junit-vintage-engine而需要显式回滚到JUnit 4:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter</artifactId> </exclusion> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> <exclusion> <groupId>org.mockito</groupId> <artifactId>mockito-junit-jupiter</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> </dependency> </dependencies>
DataSource 健康监控
该DataSource健康指标包含一个额外的validationQuery与反对使用的验证查询属性DataSource。同样,该hello属性提供的查询结果已重命名为result。
Freemarker模板配置
此版本更改了Freemarker模板的默认模板文件扩展名。这可以使Spring Boot与Web应用程序的安全配置默认值保持一致。升级时,请将现有模板从重命名*.ftl为*.ftlh。
DevTools配置目录
现在,全局DevTools设置的首选位置是~/.config/spring-boot。可以使用以下任何文件:
- spring-boot-devtools.properties
- spring-boot-devtools.yaml
- spring-boot-devtools.yml
@ConfigurationPropertiesScan
@ConfigurationProperties现在可以通过类路径扫描找到带注释的类,以替代使用@
EnableConfigurationProperties或@Component。添加@
ConfigurationPropertiesScan到您的应用程序以启用扫描。
在Spring Boot 2.2.0中默认启用了配置属性扫描,但是从Spring Boot 2.2.1开始,您必须使用进行选择@
ConfigurationPropertiesScan。
@ConstructorBinding
配置属性现在支持基于构造函数的绑定,该绑定允许带@ConfigurationProperties注释的类不可变。可以通过使用注释一个@ConfigurationProperties类或其构造函数之一来启用基于构造函数的绑定@ConstructorBinding。现在可以在配置属性绑定提供的构造函数参数上使用诸如@DefaultValue和的注释@DateTimeFormat。
Spring Boot 2.2中的弃用
- 该logging.file属性已重命名为logging.file.name。
- 该logging.path属性已重命名为logging.file.path。
- server.connection-timeout不建议使用该属性,而应使用服务器特定的属性,因为它们的行为并不完全相同。
- server.use-forward-headers不赞成使用该财产server.forward-headers-strategy; 以前server.use-forward-headers=true会使用Web服务器的本机支持。现在,您可以使用实现相同的功能server.forward-headers-strategy=native。由于每个服务器都有特定的行为,因此我们现在提供一种替代方法,该替代方法依赖于Spring的ForwardedHeaderFilter:server.forward-headers-strategy=framework。开发人员应使用最适合其用例的选项。
- ReactiveWebServerApplicationContext#getWebServerFactory。
- agentMaven插件的属性已重命名为agents。
- 不赞成使用Joda的时间支持java.time。
- ApplicationHealthIndicator赞成的PingHealthIndicator,就是始终贡献。
- ConfigurationBeanFactoryMetadata赞成ConfigurationPropertiesBean。
- ConfigurationPropertiesBindingPostProcessor赞成@EnableConfigurationProperties或register方法的构造函数。
- ConfigurationPropertiesBindingPostProcessor.VALIDATOR_BEAN_NAME已移至EnableConfigurationProperties.VALIDATOR_BEAN_NAME。
- ConfigurationPropertiesBindingPostProcessorRegistrar赞成@EnableConfigurationProperties。
- WebTestClientBuilderCustomizer已移至org.springframework.boot.test.web.reactive.server。
作者:恒宇少年
链接:
https://juejin.im/post/5de72f9b6fb9a016153dc537
猜你喜欢
- 2025-06-13 SpringBoot权限炸场!动态鉴权提速10倍吊打RBAC(附工具源码)
- 2025-06-13 Spring Boot 3.4 新特性实战解析(springboot最新)
- 2025-06-13 SpringBoot 2.7.10、3.0.5 发布,修复 DoS漏洞
- 2025-06-13 springboot(二十八)stomp在spring5.3以上报跨域问题的处理
- 2025-06-13 还在为 Spring Boot3 动态配置发愁?一文教你轻松搞定!
- 2025-06-13 SpringBoot几种动态修改配置的方法
- 2025-06-13 Spring Boot3 应用打包成 Docker 镜像全攻略
- 2025-06-13 Spring Boot3 动态配置实现方案全解析,你掌握了吗?
- 2025-06-13 Spring Framework 6.2 和 Spring Boot 3.4 为 2025 年新一代做好准备
- 2025-06-13 我找到了一个快速定位SpringBoot接口超时问题的神器
- 最近发表
- 标签列表
-
- newcoder (56)
- 字符串的长度是指 (45)
- drawcontours()参数说明 (60)
- unsignedshortint (59)
- postman并发请求 (47)
- python列表删除 (50)
- 左程云什么水平 (56)
- 计算机网络的拓扑结构是指() (45)
- 编程题 (64)
- postgresql默认端口 (66)
- 数据库的概念模型独立于 (48)
- 产生系统死锁的原因可能是由于 (51)
- 数据库中只存放视图的 (62)
- 在vi中退出不保存的命令是 (53)
- 哪个命令可以将普通用户转换成超级用户 (49)
- noscript标签的作用 (48)
- 联合利华网申 (49)
- swagger和postman (46)
- 结构化程序设计主要强调 (53)
- 172.1 (57)
- apipostwebsocket (47)
- 唯品会后台 (61)
- 简历助手 (56)
- offshow (61)
- mysql数据库面试题 (57)