Yesterday, Spring officially released the last feature version of Spring Boot this year: 2.6.0
At the same time, the end of 2.4.x
So what new features does this new version bring? Let's take a look with DD!
Important features
1. Servlet application supports configuring SameSite attributes in Cookie
This property can be configured through the server.session.cookie.same-site property, and there are three optional values:
- Strict strict mode, you must request the same site to send cookies
- Lax loose mode, cookies can be sent for secure cross-site requests
- None prohibits SameSite restriction and 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 separate management ports for actuator endpoints for security purposes. Having a separate port may lead to unreliable health checks, because even if the health check is successful, the main application may not work properly.
The traditional configuration in the past put all Actuator endpoints on a single port, and put the health group used to detect the status of the application under the additional path of the main port.
3. Enhance the /info endpoint and add 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 through this property:
management.info.java.enabled=true
4. Support using WebTestClient to test Spring MVC
Developers can use WebTestClient to test WebFlux applications in a simulated environment, or test any Spring Web applications against a real-time server.
After this enhancement, developers can use @AutoConfigureMockMvc annotated classes in the Mock environment to easily inject WebTestClient. Writing tests in this way is much easier than before.
5. Add automatic configuration of spring-rabbit-stream
This update adds the automatic configuration of Spring AMQP's new spring-rabbit-stream module.
When the spring.rabbitmq.listener.type property is set to stream, StreamListenerContainer is automatically configured.
spring.rabbitmq.stream.* properties can be used to configure access to the broker, spring.rabbitmq.listener.stream.native-listener can be used to enable native listener
6. Support custom desensitization of /env endpoint and configprops configuration properties
Although Spring Boot can handle the sensitive values in the /env and /configprops endpoints before, it only needs to be controlled by configuration properties. But there is another situation where the user may wish 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. This type of custom desensitization rule can be configured by adding @Bean of type SanitizingFunction.
Conveniently recommend the free tutorial I have been serializing: Spring Boot tutorial can be clicked directly! . It is different from many other tutorials. This tutorial does not only take into account the 1.x and 2.x versions. At the same time, for each update, some related content will be selected to repair Tips, so readers at various stages will have some long-term gains. If you think it's good, remember to forward and support it!
Other changes
1. Reactive Session Personalization
The current version can dynamically configure the validity period of the reactive session
server.reactive.session.timeout=30
2. Redis link automatically configures the link pool
When commons-pool2.jar is included in the application dependencies, the redis link pool will be automatically configured (all supported by Jedis Lettuce). If you want to close, pass the following properties:
spring.redis.jedis.pool.enabled=false
spring.redis.lettuce.pool.enabled=false
3. Build information personalization
- build-info.properties automatically generates this build information through spring-boot-maven-plugin
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludeInfoProperties>
<excludeInfoProperty>version</excludeInfoProperty>
</excludeInfoProperties>
</configuration>
</plugin>
4. New Metrics in Metrics
Two new indicators for application launch:
application.started.time: 启动应用程序所需的时间
application.ready.time: 启动应用到对外提供服务所需时间
Two indicators of disk space:
disk.free: 磁盘空闲空间
disk.total: 磁盘总空间
5. Docker image construction
Enhance the function of docker-maven-plugin plug-in:
- Set tags for custom mirroring
- Network configuration parameters, which can be used in the build process of Cloud Native Buildpacks
- Support the use of buildCache and launchCache configuration parameters to customize the name of the cache layer, which is provided by the build package to the built image
6. Remove the outdated attributes in version 2.4
Since the 2.4 version has completed the historical mission, a large number of expired attributes have been removed, and those who want to upgrade recently must pay attention to this part of the content, because your original configuration will become invalid!
Some properties of Spring MVC and servlet:
Old attributes (removed) | New attribute |
---|---|
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 |
Regarding changes to Elasticsearch properties:
Because there is a lot of content, it is not completely posted here. If you are interested, you can check the official information in the reference materials at the end of the article.
7. By default, Bean circular references are completely prohibited
Remember this article I posted a few days ago: Why IDEA does not recommend you to use @Autowired?
Some netizens ridiculed the way to encourage everyone to use the constructor.
Then after 2.6.0, if the small partner still feels that the circular dependency does not matter, they still insist on using the following model:
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 the Shishan project, such a requirement may be painful for developers. Therefore, you can also release the requirement of disallowing circular dependencies through the following configuration:
spring.main.allow-circular-references=true
8. SpringMVC default path matching strategy
The default strategy of Spring MVC handler mapping matching request path has been changed AntPathMatcher PathPatternParser .
Actuator endpoints now also use PathPattern-based URL matching. It should be noted that the path matching strategy of the Actuator endpoint cannot be configured through configuration properties.
If you need to switch the default back to AntPathMatcher, 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 analysis of the Spring Boot 2.6 version is over here.
Finally, I recommend the free tutorial I have been serializing: Spring Boot tutorial can be clicked directly!
It is different from many other tutorials. This tutorial does not only take into account the 1.x and 2.x versions. At the same time, for each update, some related content will be selected to repair Tips, so readers at various stages will have some long-term gains. If you think it's good, remember to forward and support it!
Reference
- https://spring.io/blog/2021/11/19/spring-boot-2-6-is-now-available
- https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.6.0-Configuration-Changelog
- https://www.oschina.net/news/169783/spring-boot-2-6-0-released
Well, that's all for today's study! If you encounter difficulties in the learning process? You can join our super high-quality Spring technical exchange group , participate in exchanges and discussions, and learn and progress better! More Spring Boot tutorials can be clicked directly! , welcome to collect and forward support!
Welcome to pay attention to my public account: Program Ape DD, to share knowledge and thoughts that can not be seen elsewhere
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。