Invited tutor :MIC
10 years Java EE Employment experience , Worked in Ping An 、 Public comment 、 Dig money and other Internet financial companies ,《Spring Cloud Alibaba Micro service principle and practice 》 author .
Participation in the project : Ping An pay one wallet 、 The project of digging wealth and treasure in Shanghai
A very obvious phenomenon , Except for some old projects , Now? Java Back end projects are basically based on Spring Boot Development , After all, it's easy to use and natural microservices are friendly . No exaggeration ,Spring Boot yes Java One of the most important technologies in the back end , Master it well for Java Programmers matter .
In this article, I will show you Spring Boot Principle , To help you learn more about Spring Boot.
01 What is? spring Boot?
Spring Boot Provides a quick build Spring Dramework Application framework . It is designed to simplify Spring Application initial build and development process . The framework is configured in a specific way , This eliminates the need for developers to define boilerplate configurations .
Spring Boot How to simplify ? Convention over configuration , Reduce configuration by convention , So as to improve the development efficiency .Spring Boot kernel ->(Spring Framework> Convention is better than configuration )
Convention is better than configuration
① default Maven structure , And the default packaging method
② Default profile application.properties
③Starer Correlation jar Packet dependency
④Web Default includes Spring-mvc And built in tomcat Containers
⑤ Deploy to tomcat
How not Spring Boot
① introduce jar package
② modify web.xml, Add listening and blocking
③ establish spring mvc Core profile dispatcher-servlet.xml
④ establish controller
⑤ Deploy to tomcat
02 Think deeply or simplify the principles behind
Spring Annotation driven development from XML Configuration era to annotation driven era . The details are as follows :
Spring 1.x Annotation drives the age of enlightenment
Spring 1.x Support Annotation, Although the framework level has already supported @managedResource and @Transactional( Business note ) Etc , But mainly with XML Configuration is subject to .
Spring 1.x What functions are provided ?
Provide Spring Container to host Bean object ——Bean By describing an object ,Spring This configuration will be loaded , And initialize and save .
Spring 2.x Annotation driven transition period
Spring 2.x stay Anonotation New members have been added to the support side ,@Required、 Data related @Repository And AOP dependent @Aspect etc. , But it also improves XML Configuration capability , namely “ Extensible XML To write ”.xml+ How to annotate , Can't break away completely from xml.
defects :bean The maintenance work has become very heavy .
Spring 2.x Provide comments :
@Reqired
@Repository
@Aspect
@Component
@Service
@Controller
for instance :
If you scan the current tag , So it means the current bean Will be loaded .
Spring 3.x Annotations drive the golden age
Spring 3.x It's a milestone era , stay 3.0 In the era, in addition to ascension Spring Pattern annotation “ The derived ” The hierarchy of , And replace the traditional ones with annotations XML The description of form . Replace XML Configuration mode , Introduce configuration class annotation @Configuration.
Spring 3.x Provide comments :
@Configuration
@CompomentScan
@Import- Import
Spring 4.x Annotation driven era of perfection
Spring 4.x after , Introduce conditional annotations @Conditional. By customizing Condition To achieve coordination , Make up for the previous version of conditional assembly shortcomings ,4.0 Start Profile To pass in turn @Conditional Realization .
Spring 5.x Annotation drives the age of maturity
Spring 5.x As Spring Boot2.0 The bottom of the , Annotation driven performance improvements are not obvious . stay Spring Boot In the application scenario , A lot of use @ComponentScan scanning , Lead to Spring Parsing time-consuming annotations . therefore ,5.0 Introduction of the times @Indexed, by Spring Schema annotations add index .
The meaning of annotation driven is simplification Bean Principle , Describe a need to be Spring IOC Container managed objects .
03 summary
Spring Boot yes Java Technologies that are often used in the back end domain , I hope this article can help you master Spring Boot principle , To be better Javer.