How it works...

The real essence of why developers choose Spring Boot 2.0 in building applications is the principle of auto-configuration. Unlike in ground-up Spring MVC 5 development, choosing the compatible Maven artifacts to the existing Spring API version is not a problem anymore because of the presence of the parent starter POM. The only challenge is just the choosing of the external support dependencies not included in the parent starter, since the version numbers are of critical importance. For clarification, Spring Boot 2.0 is not a framework and will not replace Spring 5 since its mandate is to generate Spring 5 applications.

There is a list of starters that can be inherited from the Maven repository of Spring Boot 2.0.0.M2 and each has auto-configuration classes found in org.springframework.boot.autoconfigure.*. To manage these classes, the bootstrap class, which is also called the Application class, will enable and execute some of them with the required properties to be filled in the application.properties file. This class, like our HRBootApplication, must have a class-level @SpringBootApplication to register it as the entry-point of the application. Another option is to apply @Configuration, @EnableAutoConfiguration, and @ComponentScan collectively in order to declare an Application class. These three annotations are needed if we need to further customize further the bootstrapping details, just like the version of our HRBootApplication in the following snippet that completely bypasses FreeMarker and Thymeleaf auto-configuration processes:

@Configuration 
@ComponentScan("org.packt.spring.boot") 
@EnableAutoConfiguration(exclude={ FreeMarkerAutoConfiguration.class,  
   ThymeleafAutoConfiguration.class}) 
public class HRBootApplication extends  SpringBootServletInitializer  { 
    // refer to sources 
} 

The HRBootApplication is composed of two methods, namely the main() and the configure() method overridden from org.springframework.boot.web.servlet.support.SpringBootServletInitializer. If the project is needed to be deployed as a standalone JAR application, the main() is required to be present to bootstrap the application. If the project needs to be deployed in an application server, the class must extend SpringBootServletInitializer to bootstrap in a servlet container using the overridden method, configure().

During bootstrap, all bean components are instantiated and injected and one of them is the org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext, which is the context root of the non-reactive Spring MVC application. All the required properties are categorized according to auto-configuration class and are found in https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html. Depending on what starter POMs are loaded into the container, necessary properties are to be registered and configured in the application.properties in order to load all the configuration beans into the ApplicationContext container.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.240.196