Some time ago, someone asked me about the difference between Spring and SpringBoot in the interview. Although Barak talked a lot at that time, now I feel that my thinking is not very clear.

So let’s do a little bit of rearranging here. Due to my understanding of the content is limited, there may be some deviation, but also please forgive me.

Spring

Let’s start with Spring, which is the SpringFramework, the platform on which Spring works. If software development is like building a house, Spring’s main role is to manage all the materials needed in the process: bricks, cement, steel… At the same time, such work as cement, sand, stone, water these ratio combination. Summarize two points: material warehouse and organization management. This is the IOC of Spring.

At the same time, Spring’S AOP functionality also provides horizontal access to all levels of software engineering process, for a class of work to do a unified function extension.

But it’s not just Spring on the market. If we want a database, we might use myBatis. If we want distributed services, we might use Dubbo. If you want to cache, you might use Redis. How does all this fit into the Spring workbench? Vendors then provide their own access packages to host the components used by these technologies into the Spring container through SpringBean definitions and various Spring processors.

Everything seems perfect so far, and anyone who wants to plug in can host themselves to it according to Spring’s access specification. So is there room for improvement?

Before SpringBoot, the introduction of components, hosting to the Spring container, and versioning were all up to the architects, and the wrong things could happen. I believe that before this, each big factory must also consider how to define a set of rules to deal with this kind of thing uniformly. And SpringBoot was born.

SpringBoot

The first is automatic assembly. There is no new technology in this part, but rather a set of specifications for external component access based on Spring’s existing capabilities. We can see that the @import annotation used on the @EnableAutoConfiguration annotation, the SPI implementation of SpringFactories, and Conditional used in configuration classes are all actually provided by Spring.

SpringBoot implements a solution for managing third-party components based on these technologies. Think back to what we did when we introduced a component in Spring. First Maven introduced dependency packages and then added configuration (configuration class or XML, etc.).

So what does SpringBoot do? Maven introduces the dependent starter (no version number required). SpringBoot already organizes most of the components on the market, and the corresponding configuration classes take effect when users rely on the corresponding starter.

What are we saving? It is important to mention that SpringBoot has a convention that when it detects a dependency on a component in a project, SpringBoot assumes by default that the user needs to import that component and the corresponding configuration class takes effect. That is, conventions are greater than configurations. This realization is achieved in Conditional form.

What if Spring does not support Mybatis? SpringBoot provides the ability to customize a starter, so you only need to customize a starter according to the specification.

To recap, SpringBoot organizes the configuration classes for each component and makes them work through user-defined starter. In other words, when users import third-party components, they no longer need to define how to hand them over to Spring for hosting. SpringBoot does it for you. All you need to do is tell SpringBoot what you want to use.

And then the actuator. Since SpringBoot organizes the components, how do you ensure that they are healthy and in good use? So that’s where the actuators come in. The SpringBoot actuator provides a comprehensive set of features that make it easy for users to monitor incoming components.

conclusion

Ok, now back to the original question, what is the difference between Spring and SpringBoot? Spring is the foundation platform that provides basic capabilities such as object management and AOP operations in software development.

SpringBoot is an extension of component dependency, providing a complete component dependency mechanism and monitoring mechanism for dependent components.

This article is all about personal understanding. Limited and personal technical ability, there may be some inaccuracies, but also please correct.

The article continues to update, wechat search "Java source", after the first time to receive push technical articleCopy the code