springBoot and spring The relationship between
First of all, clear SpringBoot Is based on Spring Of . In our actual use Spring Boot In the process of project development , It usually takes only a few simple annotation configurations to get the application running , Compared to traditional Spring It's just a project , This improvement has greatly improved our R & D efficiency . However , This kind of convenience is realized by high-level encapsulation . So how does this high level of generation encapsulation come from ？
JDk1.5 After the introduction of annotation function ,spring The framework implements a large number of annotations to replace the original ones based on xml Configuration of , It is mainly used for configuration management 、Bean And AOP And other related functions . However , With Spring There are more and more annotations , And it's used a lot , In especial The same multiple annotations are used repeatedly in various classes or methods . So you This leads to cumbersome configuration and a lot of redundant code .
How to solve redundancy ？springBoot It is for this reason that , Combine existing annotations by defining some new annotations , So for most common scenarios , Just introduce a new annotation , It automatically includes other related spring annotation .
And about the JDK If you want to annotate to another annotation , You need to define it as a meta annotation , So called meta annotations , It's a comment that can be annotated to other annotations , The annotated annotation is the combined annotation we mentioned above . and Spring Many of the annotations of the framework can be used as meta annotations , also Spring The framework itself implements a lot of composite annotations , For example, we often use annotations @Configuration It's a combination of these annotations . therefore , With such a condition Spring Boot The implementation of the basic conditions ！
therefore springBoot The essence of the framework is to achieve a lot by combining annotations spring The combination of annotations , Thus greatly simplifying spring The tedious configuration of the framework itself , Achieve rapid integration and development .
Convention over configuration
This is to describe springBoot The most commonly used description , Some people interpret it as ： Convention over configuration , Agreement is better than configuration , Habit is greater than configuration .
use springBoot Framework development program , The default values provided by the framework will make our project development more efficient , If the default value doesn't meet our needs , We can use Properties Configuration files and YAML Configuration file to override the default values to meet our needs , therefore Convention over configuration , It means less configuration by convention , So as to improve the development efficiency .
And conventions are greater than configuration , It's not a new idea , stay JDK5.0 Release , Using metadata , Introduce the concept of annotation （ It's also called tagging ）, It's the beginning of simplified configuration , It's an early kind of “ Convention over configuration ” The embodiment of ; So the design concept of convention is better than configuration , from Spring The annotated version of has already started . Annotations are introduced to reduce some of the default configuration , The introduction of annotations also represents the beginning of simplified configuration , Officials say it's based on spring It's based on the fact that .
that SpringBoot What are the conventions in ？
1、Maven Directory structure of . The default is resources Folder , Store the resource configuration file .src-main-resources,src-main-java. The default compiled classes are all in targe Under the folder
2、spring boot The default configuration file must be , It can only be application. Named yml Documents or properties file , And only
3、application.yml Default properties in . Database connection information must be in the form of spring: datasource: The prefix ; Multi environment configuration . This property can automatically read different configuration files according to the running environment ; Port number 、 Request path, etc
4、SpringBoot Appointment , When you import spring-boot-starter-web after , It's agreed that you are a web development environment . It was agreed that you would use SpringMVC. As for the rest, also agree that you will need , All are imported by default . When you don't feel right , You can use fewer changes , Meet your needs .
5、 When we import spring-boot-starter-web after , It will automatically import springMVC And a built-in dependency tomcat Containers , as well as spring-boot-starter-logging rely on . This allows you to go directly through main Method or JAR The package runs on its own WEB project .
6、SpringBoot It is agreed that starter Reduce dependence in the form of , So a lot of commonly used starter.
What's the deal , Thank you for adding .
本文为[Wooden pine cat]所创，转载请带上原文链接，感谢