29

Spring Boot 2.2 正式发布,大幅性能提升 + Java 13 支持 | 程序猿D...

 4 years ago
source link: http://blog.didispace.com/spring-boot-2-2-release/?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

之前 Spring Boot 2.2没能按时发布,是由于 Spring Framework 5.2 的发布受阻而推迟。这次随着 Spring Framework 5.2.0 成功发布之后,Spring Boot 2.2 也紧跟其后,发布了第一个版本:2.2.0。下面就来一起来看看这个版本都更新了些什么值得我们关注的内容。

组件版本更新

这些Spring框架组件更新了依赖版本:

  • Spring AMQP 2.2
  • Spring Batch 4.2
  • Spring Data Moore
  • Spring Framework 5.2
  • Spring HATEOAS 1.0
  • Spring Integration 5.2
  • Spring Kafka 2.3
  • Spring Security 5.2
  • Spring Session Corn

框架中涉及的第三方包也更新了依赖版本:

  • Elasticsearch 6.7
  • Flyway 6.0
  • Jackson 2.10
  • JUnit 5.5
  • Micrometer 1.3
  • Reactor Dysprosium
  • Solr 8.0

大幅的性能提升

关于Spring Boot的性能问题是我们经常在内容平台上看到吐槽的关键词。这次在Spring Boot 2.2中,针对性能这一点,做了大幅的优化。应用程序的启动速度将变得更快,内存占用也会变得更少。

同时,为了加快应用的启动,还增加一个全局延迟初始化的配置参数spring.main.lazy-initialization,这可以让我们的应用更快的完成启动动作,但是值得注意的是,延迟启动也会有下面这些副作用:

  • 应用在进行延迟初始化的时候,HTTP请求的处理会需要更长的时间
  • 原本可能在启动期出现的错误,将延迟到启动的运行期间出现

Java 13的支持

由于Spring Framework 5.2增加了对Java 13的支持,所以Spring Boot 2.2也自然增加了这一特性。同时,Spring Boot 2.2对于老版本的Java 11、Java 8依然支持良好。所以,对于还在使用Java 8的用户也可以安心的升级使用。

不可变的 @ConfigurationProperties 绑定

配置属性现在支持基于构造函数的绑定,该绑定允许@ConfigurationProperties注解修饰的类是不可变的。可以通过使用@ConstructorBinding注解修饰@ConfigurationProperties类或其构造函数之一来启用基于构造函数的绑定。可以在配置属性绑定提供的构造函数参数上使用@DefaultValue和@DateTimeFormat之类的注释。

更多详细信息参阅文档:https://docs.spring.io/spring-boot/docs/2.2.0.RELEASE/reference/html/spring-boot-features.html#boot-features-external-config-constructor-binding

RSocket 支持

已为RSocket添加了自动化配置的starter实现:spring-boot-starter-rsocket。当项目依赖了spring-security-rsocket的时候,该starter还会自动配置Spring Security对RSocket的集成实现。

更多详细信息参阅文档:https://docs.spring.io/spring-boot/docs/2.2.0.RELEASE/reference/html//spring-boot-features.html#boot-features-rsocket

健康检查的分组支持

现在可以将Spring Boot Actuator中各种各样的健康指标实现分组。如果将应用程序部署到Kubernetes,一个典型的需求是您可能需要不同组的健康指标来进行“liveness”和“readiness”的探测。这个时候,我们就可以通过配置属性来定义不同的分组,比如:下面创建了一个仅具有DataSource指示器的自定义组:

management.endpoint.health.group.custom.include=db

通过访问localhost8080/actuator/health/custom,就可以访问自定义的组了。

更多详细信息参阅文档:https://docs.spring.io/spring-boot/docs/2.2.0.RELEASE/reference/html//production-ready-features.html#health-groups

Release Notes中还记录了许多其他更改和改进。读者可以通过下方链接查看更多更新内容:

https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.2-Release-Notes


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK