Recently, I interviewed a lot of people, some of whom said they were very familiar with Spring Boot. When I asked them about some core functions and principles of Spring Boot, no one could tell me what they were doing.
Here’s my question:
I see it says you’re familiar with Spring Boot. Can you tell me why we use Spring Boot?
Here are the three most common answers:
A: Spring Boot does not use XML configuration. Beans can be configured in Java, eliminating many configuration files.
What does Spring Boot have to do with Java configuration instead of XML configuration?
And then the other person squeaks…
B: Spring Boot is used to do Spring Cloud microservices.
I asked: What does microservices have to do with Spring Boot? How about not using Spring Boot?
And then the other person squeaks…
C: Spring Boot can be deployed in JAR packages and is internally integrated with Tomcat.
This is certainly a Spring Boot feature, but I still feel like I missed the point.
Then I went on to ask, what if you don’t consider Jar deployment, and that’s it…
The most important feature of Spring Boot is: automatic configuration.
Why automatic configuration?
SpringBoot starts with @springBootApplication, which consists of three annotations:
- @Configuration
- @ComponentScan
- @EnableAutoConfiguration
Spring Boot: Spring Boot: Spring Boot: Spring Boot: Spring Boot See this article: Three notes at the heart of Spring Boot.
The @enableAutoConfiguration annotation is at the heart of Spring Boot. It dynamically loads configuration and injection beans based on jar packages and configurations in the classpath.
For example, if I set up a Druid connection pool Jar in lib and set druid-related parameters in the application.yml file, Spring Boot will automatically configure everything we need. If I remove the JAR package or remove the parameters, Spring Boot will not be configured automatically.
So we can do a lot of things as common, self-configured starters, and that’s exactly what the Druid connection pool does. It provides a Spring Boot-specific starter: druid-spring-boot-starter.
With this auto-configured initiator, we can use it very easily,
Add Jar package dependencies first:
< the dependency > < groupId > com. Alibaba < / groupId > < artifactId > druid - spring - the boot - starter < / artifactId > < version > 1.1.10 < / version > </dependency>Copy the code
Add related parameters:
Spring. The datasource. Url = spring. The datasource. The username = spring. The datasource. Password =...Copy the code
In a traditional project, we would have to manually write a lot of configuration, and it’s not flexible. With this launcher, we can do simple integration. Druid-spring-boot-starter can be used as a starter, but the starter can be used as a starter.
So, that’s the heart of Spring Boot, and that’s why we use Spring Boot. If you don’t answer this key point, you’re missing the heart of Spring Boot.
Say this hope to everybody some substantive help!