Yesterday, Spring officially released the last Spring Boot feature release of the year: 2.6.0
It also announced the end of version 2.4.x.
So what new features does this release bring? Follow DD to see below!
Important features
1. Servlet applications support the configuration of SameSite properties in cookies
This property can be through the server. The session. Cookies. Same – site property to configure, there are three optional value:
- Strict Indicates Strict mode. Cookies can be sent only when the request is made on the same site
- Lax Lax mode, secure cross-site requests can send cookies
- None disallows SameSite restrictions and must be used in conjunction with Secure
2. You can configure health groups for the master application port and management port
This is useful in cloud service environments such as Kubernetes. In this environment, it is common to use separate administrative ports for executor endpoints for security purposes. Having separate ports can lead to unreliable health checks because the main application may not function properly even if the health check succeeds.
In traditional configurations, all the endpoints are placed on a single port and the health group used to detect application status is placed under an additional path to the main port.
3. Enhance the /info endpoint to add Java Runtime information
Examples of enhancements:
{
"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"}}}Copy the code
This information can be turned on or off with this property:
management.info.java.enabled=true
Copy the code
4. Support using WebTestClient to test Spring MVC
Developers can use WebTestClient to test a WebFlux application in a simulated environment or any Spring Web application against a live server.
With this enhancement, developers can easily inject WebTestClient using @AutoConfiguRemockMVC annotated classes in Mock environments. This makes writing tests much easier than before.
5. Add spring-Rabbit-Stream automation
This update adds automatic configuration for Spring AMQP’s new Spring-Rabbit-Stream module.
When spring. The rabbitmq. Listener. The type attribute is set to the stream, StreamListenerContainer is automatic configuration.
Spring. The rabbitmq. Stream. * attribute can be used to configure access to the broker, spring. The rabbitmq. Listener. Stream. The native – the listener can be used to enable native listener
6. Support custom desensitization of /env endpoints and configprops configuration properties
Although Spring Boot already handles sensitive values in /env and /configprops endpoints, it only needs to be controlled through configuration properties. But there is also a case where a user might want to apply cleaning depending 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. You can configure such a custom desensitization rule by adding an @bean of type SanitizingFunction.
Here’s a free tutorial I’ve been serializing: The Spring Boot tutorial is clickable! . Unlike many other tutorials. This tutorial covers both 1.x and 2.x versions. Also, for each update, we will select some relevant content patch Tips, so there will be some long-term benefits for readers of all stages. If you feel good, remember to support it!
Other changes
Reactive Session customization
In the current version, you can dynamically configure the validity period of a Reactive Session
server.reactive.session.timeout=30
Copy the code
2. Redis links automatically configure link pools
The Redis link pool is automatically configured when an application dependency contains commons-pool2.jar (Jedis Lettuce supports all applications). If you want to turn it off, use the following property:
spring.redis.jedis.pool.enabled=false
spring.redis.lettuce.pool.enabled=false
Copy the code
3. Build information personalization
- Build-info.properties is automatically generated by spring-boot-maven-plugin
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludeInfoProperties>
<excludeInfoProperty>version</excludeInfoProperty>
</excludeInfoProperties>
</configuration>
</plugin>
Copy the code
4. Metrics Added
Two new metrics for app startup:
Application. Started. Time: the time required to start the application. Application work time: the time needed for start the application to the foreign serviceCopy the code
Two metrics for disk space:
Disk. free: free disk space disk.total: total disk spaceCopy the code
5. Construction of Docker image
Enhanced functionality of the Docker-Maven-plugin:
- Set the tags tag for the custom image
- Network configuration parameters that can be used in the Cloud Native Buildpacks build process
- Support for customizing the names used for the cache layers provided by the build pack to build images using the buildCache and launchCache configuration parameters
6. Remove the expired attribute in version 2.4
Due to the historical mission completed in version 2.4, a number of outdated attributes have been removed, so please pay attention to this part of the update, because your original configuration will be invalid!
About Spring MVC and some of the servlet properties:
Old property (deleted) | New properties |
---|---|
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 |
Elasticsearch property changes:
Because the content is more, here is not completely posted, interested in the end can see the official information in the reference materials.
7. By default, circular references to beans are completely disabled
Remember this post I posted a few days ago: Why IDEA doesn’t recommend using @Autowired?
It was also ridiculed by some netizens for encouraging people to use constructors.
After 2.6.0, if you still feel that cyclic dependency is ok, you still insist on using the following mode:
Then, you will get the following error:
┌ ─ ─ ─ ─ ─ ┐ | a (field private com. The example. The demo. B com. Example. The demo. A.) write left | B (field private com. The example. The 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.Copy the code
In fact, Spring officials do this to encourage people to get into the habit of not having circular dependencies.
But for the Shitmountain project, it might be a painful requirement for the developer. So, you can also override the requirement to not allow cyclic dependencies by configuring the following:
spring.main.allow-circular-references=true
Copy the code
8. SpringMVC default path matching policy
The Spring MVC handler map’s default strategy for matching request paths has been changed from AntPathMatcher to PathPatternParser.
Actuator endpoints now use PATHpattern-based URL matching as well. Note that the path matching policies of the Actuator endpoints cannot be configured using configuration attributes.
If you need to switch back to default AntPathMatcher to spring. MVC. Pathmatch. The matching strategy set to ant – path – the matcher, such as the following:
spring.mvc.pathmatch.matching-strategy=ant-path-matcher
Copy the code
Well, that’s the end of the Spring Boot 2.6 version resolution.
Finally, one more free tutorial I’ve been serializing: The Spring Boot tutorial is click-through!
Unlike many other tutorials. This tutorial covers both 1.x and 2.x versions. Also, for each update, we will select some relevant content patch Tips, so there will be some long-term benefits for readers of all stages. If you feel good, remember to support it!
The resources
- Spring. IO/blog / 2021/1…
- Github.com/spring-proj…
- www.oschina.net/news/169783…
Well, that’s all for today’s learning! If you have any difficulty in learning? You can join our super high quality Spring technology exchange group, participate in the exchange and discussion, better learning and progress! More Spring Boot tutorials can be clicked direct! , welcome to collect and forward support!
Welcome to pay attention to my public account: program ape DD, share the outside can not see the dry goods and thinking!