As Spring Boot has been around for a few years now, the most intuitive experience for programmers is the reduction in configuration. Few can answer the core features and principles of Spring Boot. In order to find a job in the Internet winter. Today, according to what I have learned, I will publish my humble opinion about Spring Boot. The following is the scene of the examiner and the interviewer.
Here’s the interviewer’s 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.
Q: What does Spring Boot have to do with Java configuration?
And then the other person squeaks…
B: Spring Boot is used to do Spring Cloud microservices.
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
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,
- <dependency>
- <groupId>com.alibaba</groupId>
- <artifactId>druid-spring-boot-starter</artifactId>
- The < version > 1.1.10 < / version >
- </dependency>
Add related parameters:
- spring.datasource.url=
- spring.datasource.username=
- spring.datasource.password=
- …
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
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.
Finally: Welcome to Java and big data learning friends to join the Java communication learning group: 721506929 (I am waiting for you in the group ~ come to learn together)
Click the link to join the group chat [Java communication Learning group] : https://jq.qq.com/?_wv=1027&k=5cjelsQ, the group provides free architecture information and: Java engineering, high performance and distributed, high performance, simple. High architecture. Performance tuning, Spring, MyBatis, Netty source analysis and big data and other knowledge points of advanced advanced dry free live explanation can come in together to learn and exchange oh ~