How SpringBoot automatic configuration

 

SpringMVC and SpringBoot are based on Spring, the two launch time or less, just SpringMVC launched earlier.

 

About two recently seen a more popular argument:

  Spring initially using "factory mode" (the DI) and "proxy mode" (the AOP) decoupling application components. I feel very good use, so in this mode out a MVC framework (Spring with some of decoupling components), with the development of web applications (SpringMVC).

  Then, each time found a lot of developers are writing boilerplate code, in order to streamline workflow, then developed a number of "lazy integration package" (starter), this is the Spring Boot.

 

Used SSM (SpringMVC + Spring + Mybatis), will know that a lot needs its own configuration file, a little trouble;

However, different Spring Boot, to achieve automatic configuration, convention over configuration simplifies the configuration process of the spring, reduces the complexity of the project build.

 

SSM: Tomcat start the project, you need to configure the front controller, database connections, spring and so some of the core configuration file.

SpringBoot: Project start Tomcat, you need to configure only one or two properties files on it.

 

  Both are based on how Spring, that Springboot is to reduce the profile, automatically configure it? ? ?

  To achieve the core: use JavaConfig configuration and container management.

 

  In Java, everything is an object. JavaConfig configuration is achieved by creating or bean, add a property to achieve the relevant configuration. Currently, JavaConfig configuration gradually replacing xml configuration. Further, also a container object.

 

Automatic configuration can be divided into several modules:

  1, new Tomcat (), set the correlation property value.

  2, write a class that implements WebApplicationInitializer interface (Servlet specification will automatically load all the class that implements the specified interface, WebApplicationInitializer is one of the interfaces). WebApplicationInitializer can be seen as a substitute Web.xml. By implementing WebApplicationInitializer, where you can add a servlet, listener, etc., when loading a Web project will load the interface implementation class, which play the same role in web.xml.

  3, load an instance of ApplicationContext, creating management Bean (Bean is the basic unit of management of Spring, in Spring-based Java EE applications, all components are treated as Bean).

  4, create an initialization DispatcherServlet.

 

 

Common learning and common progress, if any supplement, please point out, thank you!

Common learning and common progress, if any supplement, please point out, thank you!

Guess you like

Origin www.cnblogs.com/dengguangxue/p/11530907.html