This section mainly:
1: Analysis of Spring boot Portal and @springbootapplication source detailed
Springbootapplication contains:
@SpringBootConfiguration
@ComponentScan
@EnableAutoConfiguration
This is the second Spring boot core (1) in the Edith Learning Series-Framework Learning Spring Boot Framework Study
Disclaimer: This article is Edith Java (www.kaigejava.com) original, without permission, no reprint!
One: Spring boot entry and annotation parsing
In the previous chapter, we talked about the first spring boot application in the Portal:
650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ E010d0efdab918b3ad889b8a71f3b2d6x698x330x11.png "alt=" e010d0efdab918b3ad889b8a71f3b2d6x698x330 "/>
Please click here to enter the picture description
650) this.width=650; "src=" Http://www.kaigejava.com/res/plugins/ueditor/themes/default/images/spacer.gif "alt=" Spacer.gif "/>
Description
Spring boot projects typically have *application entry classes, and the main method is in the entry class. This is the entry method for a standard Java application.
@controller: This annotation is spring. A declaration is a controller class.
@springBootApplication: This is Springboot's note.
Please see the source code for this class:
650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ E4587e788c695f4411cafdc1c312a153x1067x576x27.png "alt=" e4587e788c695f4411cafdc1c312a153x1067x57 "/>
Please click here to enter the picture description
650) this.width=650; "src=" Http://www.kaigejava.com/res/plugins/ueditor/themes/default/images/spacer.gif "alt=" Spacer.gif "/>
From the source, we can see that this annotation is actually a set of combinations of annotations.
Let's take a look at @springbootconfiguration's note.
650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ 7bc3d1b64550dba5099c1f832fa77a14x860x451x18.png "alt=" 7bc3d1b64550dba5099c1f832fa77a14x860x451 "/>
Please click here to enter the picture description
650) this.width=650; "src=" Http://www.kaigejava.com/res/plugins/ueditor/themes/default/images/spacer.gif "alt=" Spacer.gif "/>
From its source code, we can see that the note uses the @configuration annotation. So when using @springbootconfiguration annotations, you can not use @configuration annotations.
In fact, in the Springboot project to recommend the use of springbootconfiguration to replace @configuration annotations.
Come back and look at the springbootapplication annotation, which contains the @componentscan annotations.
@componentScan source code is as follows:
650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ 1ee35ce2520c7f2012b10fcd224da7eex994x576x30.png "alt=" 1ee35ce2520c7f2012b10fcd224da7eex994x576 "/>
Please click here to enter the picture description
650) this.width=650; "src=" Http://www.kaigejava.com/res/plugins/ueditor/themes/default/images/spacer.gif "alt=" Spacer.gif "/>
@conponentScan: This annotation defaults to scanning the sibling directory of the @springbootapplication class and his subdirectories.
From the Componentscan source comments We can look at:
650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ 73b117ff80e40c1f36053f6a7da55caex1149x558x32.png "alt=" 73b117ff80e40c1f36053f6a7da55caex1149x55 "/>
Please click here to enter the picture description
650) this.width=650; "src=" Http://www.kaigejava.com/res/plugins/ueditor/themes/default/images/spacer.gif "alt=" Spacer.gif "/>
Explanation of @EnableAutoConfiguration notes:
View source code and notes for this note:
650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ Bb26c88b847889617d74d3592170178dx1863x781x58.png "alt=" bb26c88b847889617d74d3592170178dx1863x78 "/>
Please click here to enter the picture description
650) this.width=650; "src=" Http://www.kaigejava.com/res/plugins/ueditor/themes/default/images/spacer.gif "alt=" Spacer.gif "/>
This annotation enables automatic configuration. From the source note we can tell that the comment will cause SPIRNG boot to automatically configure the project's configuration items based on the jar packages that are dependent on the project.
For example: We have configured spring-boot-starter-web dependencies in Pom.xml, and the project will introduce SPRINGMVC dependencies, and Spring boot will automatically configure Tomcat and SPRINGMVC. Spring boot is automatically configured as follows:
650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ 36738bf105e07207e656fff91b483978x722x304x33.png "alt=" 36738bf105e07207e656fff91b483978x722x304 "/>
Please click here to enter the picture description
650) this.width=650; "src=" Http://www.kaigejava.com/res/plugins/ueditor/themes/default/images/spacer.gif "alt=" Spacer.gif "/>
Extended:
As we learned from the above, spring boot is automatically configured based on the project's Jar dependencies, and spring boot supports automatic configuration as follows (very many. Not all):
650) this.width=650; "Src=" http://image.uc.cn//s/wemedia/s/upload/2017/ 6f3070cbeb2a1cc32359cf19d8a71c02x683x789x44.png "alt=" 6f3070cbeb2a1cc32359cf19d8a71c02x683x789 "/>
Please click here to enter the picture description
650) this.width=650; "src=" Http://www.kaigejava.com/res/plugins/ueditor/themes/default/images/spacer.gif "alt=" Spacer.gif "/>
From there we can see that many of our familiar things have been automatically configured.
Such as:
Batch processing framework Spring batch.
Cache caching
Spring Cloud
Spring JPA for data processing
MongoDB, neo4j, Redi, SOLR, etc.
If we want to, do not need spring boot automatic configuration, want to turn off the automatic configuration of an item, how to set it?
Welcome to the next article. We will answer in the next article.
Other articles in this series:
Spring Boot Framework Learn the important annotations of preschool mastery (1)-spring Java configuration method
Spring Boot Framework Learn important annotations for preschool Mastery (2)-Configure with Java configuration spring
Spring Boot Framework Learn important notes for preschool mastery (3)-read external resource profiles by annotation
Spring Boot Framework Learn important notes for preschool mastery (4)-read external resource profiles by annotation 2
Spring Boot Framework Learning 1-Understanding Spring boot and QuickStart
Spring Boot Framework Learning 2-spring boot core (1)
Welcome to the Gothic public: Edith Java
Welcome to visit Edith Personal website: www.kaigejava.com
The source of this article: HTTP://WWW.KAIGEJAVA.COM/ARTICLE/DETAIL/49
This article from the "Edith Java" blog, reproduced please contact the author!
Spring Boot Framework Learning 2-spring boot core (1)