Recently, Spring Boot 2.2 released for the developers. Below are the popular features included in this release –
Support and Upgrade
- Spring Boot 2.2 adds support for Java 13. It also continues to support previous Java versions.
- RSocket Support – Added new Spring Boot starter spring-boot-starter-rsocket.
Spring has an upgraded version of many of its dependencies. Few of them are –
- Spring Framework 5.2
- JUnit 5.5 – starter project spring-boot-starter-test provides JUnit5 by default.
- Tomcat minimum supported version is 8.5
- Hibernate minimum supported version is 5.2
- Elasticsearch 6.7
- Flyway 6.0
Enabling Global Lazy initialization
Another new feature is enabling global lazy initialization. It reduces startup time via the “spring.main.lazy-initialization” property.
Points to remember when you enable it
- For web applications, initial HTTP requests will take longer because of first-time initialization.
- Initialization related failures will occur at a later stage, which earlier used to happen at startup.
How to disable Global Lazy initialization for few beans?
- You can use @Lazy(false) annotation for the beans for which you do not want lazy initialization.
- Use of LazyInitializationExcludeFilter bean is to disable lazy initialization of beans with a specific type. You can use the following code:
JMX now disabled by default
Earlier JMX was enabled by default and used to take a considerable amount of resources, which slows down a startup that is not a good user experience. All did not use this feature, so it made sense to disable this by default, and if user want to enable then it can be done by below –
Immutable binding of configuration properties using @ConfigurationProperties
If there are few properties for a component, then we should group them in a POJO and use it. Configuration properties now support constructor-based binding. It helps immutable binding of the properties with a POJO class, which has @ConfigurationProperties annotation.
@ConfigurationProperties provide below features which are not there in @value annotation.
Spring boot provides some relaxed rules for matching environment property name with the property name in the bean.
Here the important thing to notice is “dj.my-project.user.first-name” property is following kebab case, and “dj.my_project.user.last_name” is following underscore notation, and both can map to UserProperty Pojo because of the relaxed binding feature.
A spring Boot jar contains metadata files that provide details of all supported configuration properties. These meta-data files let IDE developers offer contextual help and “code completion” when users write application.properties or application.yml data.
Fork enabled by default in Spring Boot Maven Plug-in
Spring Boot applications that use Maven plug-in for running are now “forked” by default. Fork “enabled” means it will create (“fork”) a new JVM to run the compiler. It will be a bit slower, but the isolation is better.
If you were using customized properties using “–D” then they are no longer passed to the Spring Boot application.
- specify these properties using -Dspring-boot.run.jvmArguments.
mvn spring-boot:run -Dspring-boot.run.jvmArguments=”-Dproperty1=overriddenvalue”
- There are few dedicated options also provided, for example, for enabling a profile.
- New attribute proxyBeanMethods: In this release, there is a considerable reduction in Application startup time, and memory usage by using a proxyBeanMethods=false in Spring Boot’s @Configuration classes. proxyBeanMethods is a new attribute in @Configuration annotation introduced in Spring Framework 5.2. This unique attribute is also available with an annotation like @SpringBootApplication and @SpringBootConfiguration.
- Disable Hibernate Entity Scan: Spring Boot scans JPA entities to prepare a PersistenceUnit adequately. Hibernate’s entity is redundant now, so disabled for improved performance.
- Tomcat’s MBean Registry: It is disabled by default and reduces Tomcat’s memory utilization by approximately 2MB. If you want, then you can enable it by using below – server.tomcat.mbeanregistry.enabled= true
- When a developer launches an application at development time with bootRun in Gradle or “spring-boot:run” in Maven, the JVM will be configured with flags (-Xverify:none and -XX: TieredStopAtLevel=1) to optimize it for reduced launch time.
- There is a significant reduction in configuration property binding time.
- Injection points in auto-configuration have changed only to apply when a bean creation is required.
- Beans related to Actuator endpoints are now only created if the endpoint is both enabled and exposed (via JMX or HTTP).
- Conditions on codec auto-configuration are improved so that when codecs are not in use, their configuration will not happen.
Monitoring Health Groups
Now health indicators can be organized in custom groups. These groups are configured in the property file. User “management.endpoint.health.group.<name>” property to create a health indicator group you can use and specify a list of health indicator IDs to include or exclude.
By default new group will inherit all settings similar to system health; however, if you want to override you can do this as follow:
We can monitor the group by using below https:// localhost:8080/actuator/health/custom
Monitoring Health Information
You can use health information to monitor a running application. It is very useful for monitoring software to alert someone when a production system goes down. The info exposed depends on below properties using “never” “when-authorized” “always” values.
We can configure authorized users by using below property.
Freemarker templates configuration
Spring Boot2.2 has aligned itself with safe configuration defaults for web applications. Now default Freemarker template file extension has been changed from *.ftl to *.ftlh.
Cloud Platform Kubernetes detection
ConditionalOnCloudPlatform now detects if your Spring Boot application is running on Kubernetes.
Spring Boot 2.2 has introduced a lot of performance improvement and enhancement to support other technologies. I tried to cover most of it, but for a complete list, refer to Spring Boot 2.2 Release notes.