Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard

Time:2021-2-22

When the tide recedes, we know who is swimming naked.. Pay attention to the official account.Bat’s Utopia】Open column learning, refuse to taste. this paper https://www.yourbatman.cn Included, there are spring technology stack, mybatis, middleware and other small and beautiful columns for learning.

Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard

preface

Hello, everyone. I’m brother a. On May 15, 2020 Beijing time, spring boot version 2.3.0 was officially released. With the upgrade of the next version number, some new features will come out. As a Java coder, we need to take a look at its new features. Keep the pace of technology.

Brother a learned this news “the second time”, and then experienced it on his own machine (please note: non production environment), and then combined with the official release notes of spring boot, I’ll talk about it here.


About version number

The version of spring boot code base is easy to use the naming method of “international” (my own YY)Major version number, minor version number and revision numberSo you can feel the change of it through the version number, whether you need to pay more attention when you upgrade, and so on. So here I’m going to make a wave of popular science on each paragraph of the version number of this naming method:

  • Major version number: completely incompatible. Product positioning changes, large-scale incompatibility of core API (for example, package name changes), and downward incompatibility of architecture upgrade

    • For example: configuration1. X > – 2. X; zuul1. X > – 2. X; spring boot1. X > – 2. X; netty4. X > – 5. X
  • Minor version number: relatively compatible. Generally, add new features, delete obsolete APIs, and modify some APIs that are incompatible. Generally speaking, the impact is relatively small and within the controllable range, but the upgrade should not be taken lightly,mustDo preliminary research
  • revision number: 100% compatible. Generally, it is to fix bugs, add some innocuous features, and so on. Generally, you can upgrade if you want

This time, spring boot is upgraded to version 2.3.0, which belongs toMinor version numberSo it will bring some new features, which is worth seeing.
Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard

text

Spring boot V2.2 is stillActiveSpring boot follows thePivotal OSSSupport policy to support major versions from release date3 years. However, generally speaking, when the major / minor version is released, the last major version will be supported for at least 12 months (even more than 3 years) to solve key bugs or security problems.

For the maintenance active status of other versions and the date of EOL, make the following description:

  • 2.2.xSupported versions. It will be released in October, 2019, which is now the active backbone
  • 2.1.xSupported versions. It will be released in October 2018 and will be supported until the end of October 2020
  • 2.0.x: the version whose life has ended. Released on March 2018 and stopped maintenance on April 3, 2019
  • 1.5.x: the version whose life has ended. Released in January 2017, it is the last 1. X branch, and stopped maintenance on August 1, 2019

It can also be seen from the official website that only the supported versions will be listed, which has a certain guiding role for users
Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard


Simply recall the new features of version 2.2

Obviously, spring boot 2.2 is not the focus of this article, but in order to play a bridging role, we list its core new features as follows:

  1. Spring framework 5.2: major upgrade, you can see its efforts for cloud native
  2. JUnit 5: from this release,spring-boot-starter-testDefault useJUnit 5As a unit testing framework
  3. Support java13
  4. Performance improvementThis is shown by changing all auto configuration classes to@ConfigurationIn the Lite mode, the performance is improved.
  5. newly added@ConfigurationPropertiesScanAnnotation, auto scan@ConfigurationPropertiesConfiguration class
  6. Support rsocket

Now let’s learn about the new features of the next upgrade (version 2.3.0), which is divided into main new features and other new features.


Main new features

Graceful shutdown

This new feature is deeply rooted in the hearts of the peopleIt’s good news for developers and operators. As far as I know, many small and medium-sized companies / teams use itkill -9(of course, some “gentle” teams also use itkill -2)To stop the service, this violent “shutdown” is easy to cause the failure of business logic execution, resulting in data inconsistency in some business scenarios. Although we can avoid this problem through some means (self research), not every company / team has done it. Spring boot2.3.0 has this function built inGraceful shutdown

Little knowledge: Kill – 2 is similar to your Ctrl + C, it will trigger the event of shutdownhook (thus closing the spring container); kill – 9 has nothing to say, kill

Sb has all four embedded web servers (jetty, reactor netty, Tomcat and undertow) and responsive and servlet based web applicationsBoth support elegant closure. On shutdown, the web server willNo longer allowedNew request, and give a grace period for the request waiting to be completed. Of course, this grace period can be set: it can be usedspring.lifecycle.timeout-per-shutdown-phase=xxxThe default value is 30s.

Attention, attention, attention: by default, graceful shutdown andIt's not on(or shut down immediately), you just need to addserver.shutdown=gracefulConfigure to start graceful shutdown (see the shutdown enumeration class added in 2.3.0 for the value, and see theAbstractConfigurableWebServerFactory.shutdownProperty value).


Adjustment of configuration properties

In this version, some configuration properties have been changedRenamed or discarded(this can lead to incompatibility, which needs special attention), and you need to make adjustments.

So how do I know which attributes I use now have incompatibility??? The government has given you a good solution. Here I’ll show you how to deal with it with an example

Status quo: in spring boot 2.2. X environment, you have many configurations. The pain is that you don’t know which configurations need to be replaced with the new ones in 2.3. X. At this time, you can add this jar in the project

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-properties-migrator</artifactId>
    <scope>runtime</scope>
</dependency>

thenUpgrade your spring boot to version 2.3.0, restart the project. This is from your profilespring.http.encoding.enabled=trueFor example, because the latest version of sb is used, you can see the following log output on the console:

Property source 'applicationConfig: [classpath:/application.properties]':
    Key: spring.http.encoding.enabled
        Line: 3
        Replacement: server.servlet.encoding.enabled

Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard
The log says it’s clear enough. With this good helper, mom doesn’t have to worry about so many hot configuration items. She needs to check them one by one and modify them one by one according to the instructions.

Official note: after the migration is complete, make sure to remove the dependencies from the projectproperties-migratorThis module.

By the way, when upgrading to version 2.3.0, the main changes are as follows:spring.http. -> server.servlet.encoding.、spring.mvc.、spring.codec.


Delete classes / methods / properties that are not recommended

In this release, spring boot removed theNot recommendedMost classes, methods, and properties of. Please make sure that there are no more calls to methods that are not recommended before upgrading. In view of this, the following examples are those that are “alive” but abandoned in version 2.2 (marked with@DeprecatedNote), but has been changed in version 2.3Delete completelyClass, method and property of:

  1. Method bindresult # orelsecreate
  2. Property loggingapplicationlistener # logfile_ BEAN_ NAME
  3. Class jodadatetimejackson configuration
  4. Class jestautoconfiguration

Even so, some have been abandoned in 2.2, but still exist in 2.3.0, such as:ConfigurationBeanFactoryMetadata、CompositeHealthIndicator


The configuration file location supports wildcards

Spring boot is now loading the configuration fileSupport for wildcard location. By default, theconfig/*/Location is supported. When the configuration property hasWhen multiple sourcesFor example, inKubernetesIt’s very useful in this environment.

Feature Description: outside the jar package, outside the jar package, outside the jar package, and inside (for example, there is no such feature in the resource directory). Here is an example to prove it

In short, if you have MySQL configuration and redis configuration, you can place them separately, with better isolation and clearer directory

  • mysql:/config/mysql/application.properties
  • redis:/config/redis/application.properties

The project contents are as follows:
Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard
Running program:

public static void main(String[] args) {
    ConfigurableApplicationContext context = SpringApplication.run(Boot23Demo1Application.class, args);

    ConfigurableEnvironment environment = context.getEnvironment();
    System.out.println(environment.getProperty("mysql.name"));
    System.out.println(environment.getProperty("redis.name"));

    context.close();
}

Results the output was as follows

mysql
redis

But if you put the file in the jar package, like this, it’sIt doesn’t work
Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard
The output is null, so you need to pay attention to it~


Date conversion support configuration in Web

Conversion of present time / dateCan passProperty, which complements existing support for formatting date values. For example, for MVC and Webflux, their configuration items are as follows:

  • spring.mvc.format.date
  • spring.mvc.format.date-time
  • spring.mvc.format.time
  • spring.webflux.format.date
  • spring.webflux.format.date-time
  • spring.webflux.format.time

I believe everyone knows how to use this. You can see what it means at a glance. But, but, but:Please do a full testAnd fully consider the compatibility, because what you are moving is the interface layer~



Other new features

Change some dependency minimum version requirements

It is mainly reflected in the following two aspects:

  1. If you build with gradle, supportGradle 6.3+ . Of course5.6.xIt’s also supported, but it’s marked @ retired and not recommended
  2. If you use jetty embedded container, the version requirement isJetty 9.4.22+

Core dependence upgrade

Spring boot 2.3 is migrated to several new versions of spring projects:

  • Spring data Neumann: you can understand it as an upgrade to the previous spirit data project
  • Spring HATEOAS 1.1
  • Spring Integration 5.3
  • Spring Kafka 2.5
  • Spring Security 5.3
  • Spring Session Dragonfruit

The construction of spring boot 2.3 and spring boot 2.2 based onsameSpring framework and reactor.

Note: sping core has not been upgraded, or is it version 5.2.6 (sb version 2.2.7 relies on spring core)


Third party library dependent upgrade

  • AssertJ 3.16
  • Cassandra Driver 4.6
  • Elasticsearch 7.6
  • Hibernate Validator 6.1
  • JUnit Jupiter 5.6
  • Kafka 2.5
  • Lettuce 5.3
  • Micrometer 1.5
  • MongoDB 4.0

Changes brought by spring data Neumann upgrade

  • Cassandra: upgrade to V4 with some changes, such asClusterBuilderCustomizerIt’s dead~
  • Couchbase: upgrade to V3
  • Elasticsearch: the obsolete native elasticsearch transport has been deleted directly, and the support for jest has also been removed. Starting from this release, the default support isElasticsearch7.5+
  • MongoDB: upgrade to V4

About validation

From this release,spring-boot-starter-webValidation will not be brought in any more, so if you use it, you need to add it yourselfspring-boot-starter-validationDependence:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
</dependency>

aboutspring-boot-starter-webScreenshot of the difference between the new and old versions of the starter:
Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard
Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard


Remove some Maven plug-ins

Removed yesexec-maven-pluginandmaven-site-pluginThe management of these two plug-ins, so if your project depends on these two plug-ins, then you have to display the import (specify the version number).


Support java14

Spring boot 2.3 adds support for Java 14. Of course, Java 8 and Java 11 are also supported.


Docker support

Support for building jar files with hierarchical content has been added to Maven and gradle plug-ins. Stratification basisChange frequency of jar contentTo separate them. This separation allows the docker image to be built more efficiently. An existing layer that has not been changed can be reused at the top with the changed layer.

Depending on your application, you may need to adjust how layers are created and add new layers. This can be done by describing how to divide jars into layers and how to configure the order of these layers.


Fat jar support optimization

The fat jar built with Maven and gradle now includes aIndex file. When jars are decomposed, this index file is used to ensure that the order of class paths is the same as when jars are executed directly.


Thread configuration of embedded servlet web server

The configuration properties (including jetty, Tomcat, and undertow) used to configure the threads used by the embedded servlet web server are moved to the threads focused grouperver.jetty.threadsserver.tomcat.threadsserver.undertow.threads. Of course, the old configuration properties are not availableIt’s still there, but marked as@DeprecatedIt’s not recommended anymore~
Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard


Basic path configuration of Webflux

You can now configure the basic path of all web handlers for a Webflux application. usepring.webflux.base-path = xxxto configure.


Activity detector

Spring boot now has built-in ability to detect application availability, which canTracks whether the application is activeAnd whether they are ready to handle the traffic. If you configuremanagement.health.probes.enabled=trueThen the health check endpoint can see the active and ready list of your app, which is done automatically when running on kubernetes.
Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard


Activator enhancement

The main thing is to optimize the output and display of the endpoint. For example:

  • /actuator/metrics/Arrange them in alphabetical order so that you can find them more easily
  • Datasource’sHealthIndicatorHealth indicator, now no query judgment, andConnectionIt’s just connection availability verification


When will spring cloud catch up?

As a good friend of spring boot, according to the past practice, their pace is not generally consistent. So far, what is the latest version of spring cloudHoxton SR4Does it support the latest spring boot 2.3.0??? The answer is:No, no, No. Spring boot, a cross version upgrade, usually has blocking changes, so it will take time to adapt.

No, the official announced spring cloud supportSpring Boot 2.3.xIt’s the milestone time point of the projectHoxton.SR5Release time:
Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard
Spring cloud milestone address: https://github.com/spring-cloud/spring-cloud-release/milestones


Upgrade suggestions: and so on

At least after the release of 2020-5-26, at least after spring boot2.3. X has been running for some time,Sit in the second row and watch the play, is the most comfortable and safe.


summary

This is an introduction to the new features of spring boot 2.3.0. I hope it can help you. Some people may say: anyway, I don’t use this version now, there’s no need to understand it. In fact, if you don’t understand 2.3.0 or 2.4.0, if you suddenly overuse 2.5. X from 2.0.0 one day, you will feel “uncomfortable”. Is that the truth?


Follow brother a

Author Your Batman
Personal site www.yourbatman.cn
E-mail [email protected]
WeChat fsx641385712
Active platform Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcardSpring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcardSpring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcardSpring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcardSpring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcardSpring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcardSpring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard
official account Utopia of bat (ID: bat Utopia)
Knowledge planet Bat’s Utopia
Daily article recommendation Daily article recommendation

Spring boot 2.3.0 officially released: elegant downtime, new features of configuration file location wildcard