The programming language Spring Boot 2.6.0 is officially released circular dependencies are prohibited by default, and Docker image construction is enhanced…

The programming language Spring Boot 2.6.0 is officially released: circular dependencies are prohibited by default, and Docker image construction is enhanced…

Yesterday, Spring officially released the last feature version of Spring Boot this year: 2.6.0

At the same time, the end of version 2.4.x was also announced .

So what new features does this new version bring? Let’s follow DD to see it together!

Important features

1. The servlet application supports configuring the SameSite attribute in the cookie

This property can be configured through the [server.session.cookie.same] -site property, with three optional values:

  • Strict Strict mode, you must request the same site to send cookies
  • Lax relaxed mode, secure cross-site requests can send cookies
  • None disables SameSite restrictions, must be used with Secure

2. Support configuration of health group for main application port and management port

This is useful in cloud service environments such as Kubernetes. In this environment, it is common to use a separate management port for actuator endpoints for security purposes. Having separate ports can lead to unreliable health checks, as the main application may not work properly even if the health checks are successful.

Traditional configurations put all Actuator endpoints on a single port and put the health group used to detect application state under an additional path to the main port.

3. Enhanced /info endpoint, adding Java Runtime information

Enhanced example:

{
  "java": {
    "vendor": "BellSoft",
    "version": "17",
    "runtime": {
      "name": "OpenJDK Runtime Environment",
      "version": "17+35-LTS"
    },
    "jvm": {
      "name": "OpenJDK 64-Bit Server VM",
      "vendor": "BellSoft",
      "version": "17+35-LTS"
    }
  }
}

This information can be turned on or off with this property:

spring.redis.jedis.pool.enabled=false

spring.redis.lettuce.pool.enabled=false

4. Support using WebTestClient to test Spring MVC

Developers can use WebTestClient to test WebFlux applications in a simulated environment, or to test any Spring web application against a live server.

After this enhancement, developers can use @AutoConfigureMockMvc annotated classes in the Mock environment to easily inject WebTestClient. This makes writing tests much easier than before.

5. Add automatic configuration of spring-rabbit-stream

This update adds auto-configuration for Spring AMQP’s new spring-rabbit-stream module.

StreamListenerContainer is auto-configured when the spring.rabbitmq.listener.type property is set to stream.

The spring.rabbitmq.stream.* properties can be used to configure access to brokers, and spring.rabbitmq.listener.stream.native-listener can be used to enable native listeners

6. Support custom desensitization of /env endpoint and configprops configuration properties

While Spring Boot has previously handled sensitive values ​​present in the /env and /configprops endpoints, it just needs to be controllable via configuration properties. But there is another case where the user may want to apply cleanup based on which PropertySource the property originated from.

For example, Spring Cloud Vault uses Vault to store encrypted values ​​and load them into the Spring environment. Since all values ​​are encrypted, it makes sense to desensitize the value of each key in the entire attribute source. Such custom sanitization rules can be configured by adding a @Bean of type SanitizingFunction.

I would like to recommend the free tutorial that I have been serializing: Spring Boot tutorial can be clicked directly! . Unlike many other tutorials. This tutorial covers not only 1.x and 2.x versions. At the same time, for each update, some related content will be selected to repair Tips, so there will be some gains for readers at various stages in the long run. If you think it’s good, remember to forward it to support it!

Other changes

1. Reactive Session Personalization

The current version can dynamically configure the validity period of the reactive session

org.springframework.boot
      spring-boot-maven-plugin


            version

2. Redis link auto-configure link pool

When commons-pool2.jar is included in the application dependencies, the redis link pool will be automatically configured (supported by Jedis Lettuce). If you want to turn it off then pass the following property:

application .started .time : the time it took to start the application

application .ready .time : the time it takes to start the application and provide services to the outside world

3. Build information personalization

  • Through spring-boot-maven-plugin, support build-info.properties to automatically generate this build information 

disk .free : disk free space

disk .total : total disk space

4. Metrics New Metrics

Two new metrics for app launch:

┌─────┐
|  a (field private com.example.demo.B com.example.demo.A.b)
↑     ↓
|  b (field private com.example.demo.A com.example.demo.B.a)
└─────┘


Action:

Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.

Two indicators of disk space:

disk .free : disk free space

disk .total : total disk space

5. Build the [Docker] image

Enhance the functionality of the docker-maven-plugin plugin:

  • Set tags for custom images
  • Network configuration parameters that can be used in the build process of Cloud Native Buildpacks
  • Support using the buildCache and launchCache configuration parameters to customize the names used for caching layers provided by the buildpack to the built image

6. Removed expired properties in version 2.4

Since version 2.4 has completed the historical mission, a large number of expired attributes have been removed. Friends who want to upgrade recently must pay attention to this part, because your original configuration will be invalid!

Some properties about Spring MVC and [servlet :]

old property (removed) new property
spring.web.locale spring.mvc.locale
spring.web.locale-resolver spring.mvc.locale-resolver
spring.web.resources.* spring.resources.*
management.server.base-path management.server.servlet.context-path

Changes to Elasticsearch properties:

Because there is a lot of content, it is not fully posted here. If you are interested, you can look at the official information in the references at the end of the article.

7. By default, circular references to beans are completely prohibited

Remember this post I posted a few days ago: Why IDEA doesn’t recommend you to use @Autowired?

The way of encouraging everyone to use the constructor has also been ridiculed by some netizens.

Then after 2.6.0, if your friends still feel that [circular dependencies] do n’t matter, they insist on using the following mode:

Then, you will get the following error:

┌─────┐
|  a (field private com.example.demo.B com.example.demo.A.b)
↑     ↓
|  b (field private com.example.demo.A com.example.demo.B.a)
└─────┘


Action:

Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.

In fact, Spring officially does this to encourage everyone to develop a good habit of not having circular dependencies.

But for Shishan projects, such a requirement may be painful for developers. So, you can also release the requirement of disallowing circular dependencies with the following configuration:

spring.main.allow-circular-references=true

8. SpringMVC default path matching strategy

The default strategy for Spring MVC handler mapping to match request paths has been   changed from AntPathMatcher to PathPatternParser .

Actuator endpoints now also use PathPattern-based URL matching. It is important to note that path matching policies for Actuator endpoints cannot be configured through configuration properties.

If you need to switch back to AntPathMatcher by default, you can set spring.mvc.pathmatch.matching-strategy to ant-path-matcher, such as the following:

spring.mvc.pathmatch.matching-strategy=ant-path-matcher

Well, the version analysis of Spring Boot 2.6 ends here.

Finally, I would like to recommend the free tutorial that I have been serializing: Spring Boot tutorial can be clicked directly!

Unlike many other tutorials. This tutorial covers not only 1.x and 2.x versions. At the same time, for each update, some related content will be selected to repair Tips, so there will be some gains for readers at various stages in the long run. If you think it’s good, remember to forward it to support it!

References

Well, today’s learning is here! If you encounter difficulties in the learning process? You can join our high-quality Spring technical exchange group , participate in exchanges and discussions, and learn and progress better! More Spring Boot tutorials can click directly! , welcome to collect and forward support!

Welcome to pay attention to my public number: Programmer DD, share the dry goods and thoughts that cannot be seen outside!

Article source: /didispace/p/15580132.html

Leave a Comment

Your email address will not be published. Required fields are marked *