Spring Boot Features

As we have discussed, the Spring Boot framework is built on the top of the Spring framework. It is an upgraded version of the Spring project, so it is capable of doing the things that the Spring framework can’t do.

Here, we are going to discuss the key features of the Spring Boot framework, which are listed below:

Features of Spring Boot
  • SpringApplication
  • Lazy Initialization
  • Admin Features
  • Security
  • Logging
  • Caching
  • Kotlin Support
  • Validation
  • JSON
  • Testing
  • Task Execution and Scheduling

SpringApplication

The SpringApplication class is mainly used to bootstrap and launch a Spring application using the main method. In some cases, we can also use static SpringApplication.run method, as shown below.

public static void main(String args[])

{

       SpringApplication.run(MyFirstSpring.class, args);

}

By default, the info logging messages are shown whenever a Spring application starts. This startup info logging messages can be turned off by setting spring.main.log-startup-info to false.

Lazy Initialization

In the Spring Boot framework, the SpringApplication helps in the lazy initialization of the Spring applications. After enabling the lazy initialization, beans are created as per the requirement rather than during the application startup, which results in faster execution of the application. When enabling lazy initialization in a web application, some web-related beans are not initialized until an HTTP request is received.

We can enable lazy initialization in three ways:

  • First, by using the method lazyInitialization() of the SpringApplicationBuilder class.
  • Second, by using the setLazyInitialization() method of the SpringApplication class.
  • Third, by using the property spring.main.lazy-initialization.

spring.main.lazy-initialization= true

Admin Features

In the Spring Boot framework, we can enable the admin-related features by specifying the spring.application.admin.enabled property. It displays the SpringApplicationAdminMXBean interface on the platform MBeanServer. It is used to implement the wrapper services and also administrate the Spring Boot applications.

Security

The Spring Boot applications are Spring-based applications. Therefore, the Spring Boot applications are highly secure, and it relies on the Spring Security strategies. The @EnableGlobalMethodSecurity annotation is used to add the method –level security in a web application.

Logging

The Spring Boot framework uses the Commons-logging for all the internal loggings, which is a Java-based programming model service for logging and other toolkits. Some default configurations are also provided for Log4J2, Logback, and Java Util Logging.

Caching

Caching is supported by the Spring Boot framework. It is also applied to the methods of the applications, that results in reducing the number of executions based on the information available to the cache. The Spring Boot auto-configures the cache as long as the support for caching is enabled by using the annotation @EnableCaching annotation.

Kotlin Support

Kotlin is a programming language used for Android, server-side, mobile cross-platform, and web development. It targets the JVM and other platforms that allow writing short and simple code while providing interoperability with other existing libraries of Java.

Validation

The method validation feature is automatically supported by the Spring Boot framework. It allows the bean methods to be annotated with javax.validation constraint on their fields and return values. The target classes are annotated with the @Validated annotation at level-type and searched by the validator for validation.

JSON

The Spring Boot framework offers integration with mainly three JSON mapping libraries:

  • Gson: The Gson configuration is provided by default. Therefore, it is automatically configured when Gson is on the classpath. There are several spring.gson.* Configuration properties are available for modifying the configurations. The GsonBuilderCustomizer bean is also used for controlling configurations.
  • Jackson: It is a part of the spring-boot-starter-json repository. Like Gson, the Jackson configuration is provided, by default. An ObjectMapper bean is automatically configured when Jackson is on the classpath. It also offers several configuration properties for customizing the configuration of the ObjectMapper.
  • JSON-B: The auto-configuration for JSON-B is also provided by default. A Jsonb bean is automatically configured when the JSON-B API and its implementation are on the classpath.

Jackson is the default and most preferred JSON library.

Testing

The Spring Boot framework provides a variety of utilities and annotations to help in testing the applications. There are two modules that provide test support, one is spring-boot-test that contains all the core items, and the other is spring-boot-test-autoconfigure that supports auto-configuration for tests.

Task Execution and Scheduling

If the Executor bean is absent in the context, the Spring Boot auto-configures a ThreadPoolTaskExecutor. According to the target, we can change the Executor bean to a ThreadPoolTaskExecutor or can define both ThreadPoolTaskExecutor and an AsyncConfiguration.

Pin It on Pinterest

Share This