An article takes you to understand the spring family bucket package

  What foods are in the barrel of the spring family

  In the last issue, we talked about the basic knowledge and learning route of the two frameworks of spring and springmvc. In this issue, we will discuss the spring family bucket.

  Everyone should know that in the order of appearance, the spring family bucket probably contains spring, springmvc, springboot, and springcloud. From the appetizer spring to the spring seat of the Han Dynasty, the spring family bucket can be described as a necessary meal for Java engineers. Take a look at how the spring family bucket has evolved from bare stem commander spring to today's huge family.

  Currently, the Spring ecosystem contains 22 main active projects.

  image

  You will find that these projects cover almost all scenarios of daily development, but you may not necessarily use them. In addition to spring and springmvc, springcloud and springboot, there are many open source spring ecological projects that are continuously maintained in the spring community. For example, springdata, used to solve the unified data solution in spring, spring integration, as the name suggests, is suitable for integrating external services.

  In addition, the spring security we may use in some projects is usually used to solve some security problems. This framework is also used in the industry more often.

  In addition, spring AMQP and spring Kafka integrate the corresponding message middleware in the spring framework, so that message sending and receiving can be more easily used in the framework.

  The entire Spring ecosystem contains many specific frameworks applied in specific scenarios, such as: "Spring Framework", "Spring Security", "Spring Boot", "Spring Cloud", etc., where the "Spring Framework" framework is the entire ecology The core foundation, other frameworks need to rely on the basic functions provided by the "Spring Framework", and each framework has its own independent code warehouse.

  Java engineers for spring programming

  I remember when I first started working on Java projects, I was looking for tutorials on the Internet. At that time, I have seen a lot of spring framework application projects. Basically, the online entry projects are based on SpringMVC, which may be ssm or ssh.

  In short, the tutorial will ask you to write a controller that returns a simple "hello world". If it is more complicated, you may need to access the database and use mybatis. Of course, the source code can be found on the Internet many times. You just download it and run it again. That ’s fine. Of course, the premise is that you have installed the JDK and you will use maven and ide, otherwise you may not run after downloading, and various errors will be reported. Although these problems do not exist for old drivers, believe me, this is a problem that Xiaobai often encounters.

  When I first wrote a blog, I was working on a simple ssm project. At that time, I configured all kinds of things clumsily, and finally ran the whole project, so I happily recorded the actual combat process. Going back to the original blogs, I feel like I'm really stingy.

  But this is all the novice programmers need to experience, you need to understand the basics of Java, and then understand the Java Web, to fully understand the Java Web, you must know spring, after spring, please refer to it The components are also understood, especially those that you might use in your work.

  image

  Today, I do Java in Alibaba, and the technologies I use every day are self-developed middleware. Many of these middleware technologies also absorb the essence of open source technology. You can often see the shadow of spring in their source code. The powerful influence of the spring ecosystem, even the domestic first-class Java technology team, will spend a lot of time to study and learn the spring framework source code.

  When people who do Java development mention Spring, the first words that come to mind are "IoC", "AOP", "Spring MVC", "Spring Security", etc., and even have the feeling of "no Spring is not Java" .

  In fact, today, Spring is no longer a simple programming framework. From the initial "SSH framework" to today, Struts and Hibernate are almost disappearing from the programmer's perspective, but Spring has developed into a Very large and complete ecology.

  Therefore, unless it is specifically specified as a specific framework in the Spring ecosystem, the mention of "Spring" should refer to the entire Spring ecosystem.

  It is no exaggeration to say that as long as Java programmers are proficient in Spring, they will have mastered the essence of Java development.

  Spring Framework

  In the last issue, we have introduced spring and springmvc. For the completeness of the content, please allow me to repeat it again.

  The Spring Framework project is the foundation of the entire Spring ecosystem and contains the core functions of Spring, such as: IoC, AOP, Spring MVC, etc. Other projects need to rely on the Spring Framework.

  In addition, it should also be noted that the Spring Framework project contains multiple sub-modules, such as: spring-core, spring-beans, spring-context, spring-aop, spring-web, spring-webmvc and so on.

  In fact, the Spring Framework project is a modular architecture, and there are dependencies between the modules. The Spring MVC that we use most in the Java Web background project is actually the module spring-webmvc, and its dependencies with other modules are as follows:

  image

  Obviously, the spring-webmvc module depends on spring-context, spring-aop and spring-web.

  Dependency of spring-webmvc module

  image

  springboot

  When I first came into contact with springboot, or when I was doing some internship, we were doing a private cloud, using the open source project OpenStack. OpenStack itself contains many components, some are responsible for network, some are responsible for storage, Some are responsible for scheduling, etc. All of its overall deployment methods are distributed, so it is normal to do microservice splits.

  Of course, at that time, I had no concept of microservices and only one side of springboot. I only knew that my master told me that springboot was used for microservices. Let me look at the code of a springboot project. So I looked at it for a moment, and found out that this thing and spring seem to be no different, except that the startup method is a bit strange, the xml configuration file is less, and it seems that it is not much different. .

  In fact, it is also true. Spring Boot is a scaffolding project based on Spring. It simplifies many spring and springmvc features, making it easier for novices to get started with spring development.

  For example, it integrates embedded Tomcat by default, configures annotations, supports rapid integration of third-party development components (such as MyBatis), greatly reduces the threshold for using Spring, and has built-in many functions that can be directly used in the production environment.

  In simple terms, springboot is a layer outside of springmvc, which shields some of springmvc's complicated implementation details, as well as cumbersome configuration and development processes, and turns some conventional things into specifications, forming a so-called springboot starter.

  image

  This kind of framework that supports rapid development and rapid inheritance obviously improves development efficiency, so it is currently the only choice for developing microservice architecture projects.

  However, it should be emphasized here that springboot is not equivalent to microservices. It is only an application container at best. If you compare microservices to a large network, then the springboot application is just a small point in this network, and microservices need to pass. Service gateways, load balancing, registration centers and other means connect these points, and support the downgrade and fuse of services during the operation of this network (cut off the connection to a certain point

  It is worth noting that many people who have just come into contact with Spring Boot have made it mythical, although using Spring Boot can quickly develop a robust, directly-running project, but its core and foundation come from the Spring Framework.

  For developers who rely heavily on Spring, you should go through the Spring Framework first. As long as you really master the implementation principles of each module in the Spring Framework, you will also solve the problems encountered in the actual development of using Spring Boot.

  First, what is microservices?

  Let me tell you, I haven't touched springcloud in the real sense. The reason is very simple. The technology stack I used for the development work has been contracted by Alibaba's internal middleware. All the technologies you use in springcloud are Alibaba has a corresponding set or even a few sets of implementations. Some of them have been open sourced, and some are only used internally. Anyway, you can't use open source technology in Alibaba, even if it is as strong as springcloud.

  In fact, in addition to Ali, like Java giants such as Meituan and JD.com, they also maintain their own set of self-developed technology stacks. After all, their own things are at their disposal, and problems can be repaired as soon as possible. If you use open source It ’s not embarrassing to have technology, in case one day there is a bug and the open source community asks grandpa to sue grandma.

  Although I haven't contacted springcloud in a strict sense, the set of microservices is actually a change of soup.

  Let's take a look at Baidu Encyclopedia's introduction to microservices and springcloud.

  The so-called microservices are the final product under the SOA architecture. The design goal of this architecture is to dismember the business and enable the services to run independently. Design principles of microservices: 1. Do their own job 2. Service high availability and scalability.

  Microservices is an emerging software architecture, which is to split a large single application and service into dozens of supporting microservices. A microservice strategy can make the job easier. It can extend a single component instead of the entire application stack to meet service level agreements.

  In fact, it is quite clear here that the role of microservices is to split the previous huge single application into multiple components, and each component performs its own duties. Compared with a single large service, the benefits of microservices are too much. For example, they can be deployed and tested separately to better support DevOps, make more effective use of machine resources, and make it easier to ensure scalability and availability. The following figure is the evolution process of microservice architecture.

  image

  If you still do not understand, then I will explain to you bit by bit.

  1. In terms of deployment and R & D efficiency, the deployment of a large-scale application is very slow. It takes half a day to change a bit of code. The efficiency of R & D iteration is conceivable, while the micro-service application has a small body and rapid deployment. Microservices can be independently developed and iterated, and the efficiency is naturally high.

  2. In terms of using resources and testing efficiency, a large-scale application often takes a large gap between the upper and lower limits of resources. Many times we have to allocate a large amount of resources to him, and microservice applications now support containerized deployment. Containerized deployment The biggest benefit is to support the elastic expansion of resources and improve resource utilization efficiency. For testing, a large application often needs to return to the application code with a little change. The cost can be imagined. After the microservices are split, the amount of testing will be greatly reduced.

  In addition, there are many advantages of microservices. For example, it is easier to troubleshoot problems, it is easier to expand and scale, and it can avoid single point problems.

  The following picture compares our daily life to microservices. In fact, isn't our life composed of such gears.

  image

  Of course, microservices are not all advantages, and there are naturally disadvantages.

  For example, the splitting of microservices requires a lot of cost. First of all, the application must be split. The original local service must become a distributed service, and distributed services have to face more problems than local services. Fortunately, microservices The framework has solved some of these problems.

  In addition, the split of microservices is not only the split of applications, but also the split of corresponding data sources. This involves some solutions for distributed databases, such as sub-database and table, such as distributed transactions That is to say, the split of microservices inevitably introduces many problems that are only in a distributed environment, including data consistency, network partitioning, and so on.

  image

  springcloud: the best open source solution for microservices

  Well, since the split of microservices will bring so many problems, the developers of microservice frameworks naturally thought of it, so they will use various methods to help developers solve these problems. Let us take a look at springcloud. How to do it.

  Spring Cloud is an ordered collection of a series of frameworks. It uses Spring Boot's development convenience to subtly simplify the development of distributed system infrastructure, such as service discovery registration, configuration center, message bus, load balancing, circuit breaker, data monitoring, etc., can use Spring

  Boot's development style enables one-click startup and deployment.

  Spring Cloud does not repeat the manufacturing of wheels. It only combines the mature and practical service frameworks developed by various companies. The Spring Boot style re-encapsulation shields the complex configuration and implementation principles, and finally develops The author left a set of distributed system development toolkits that are simple to understand, easy to deploy and easy to maintain.

  image

  Obviously, springcloud is prepared, and the problems caused by the split of microservices can be resolved one by one.

  For example, to split local services into distributed services, springcloud provides a service registration center and configuration center, and a unified service gateway, making distributed services as simple and easy to use as local services

  At the same time, technologies such as message bus and load balancing have solved some of the high concurrency problems in distributed environments.

  In addition, functions such as data monitoring, fusing and current limiting, distributed link tracking, cluster fault tolerance, etc., have corresponding solutions in springcloud.

  Again, springcloud is the microservices framework, and springboot is just a scaffold for rapid development of web applications. The foundation of Spring Cloud is Spring Boot. Based on Spring Boot, the process of developing microservice components can be greatly simplified.

  So far, we have introduced most of the contents of spring family bucket, I hope these contents will be helpful for you to learn spring ecological technology in the future.

  Recommended resources

  In fact, the best technical resources of spring are in the official website: https://spring.io/

  Students with good English may wish to go directly to the official documents.

  books

  Spring Boot combat, Ding Xuefeng (translator)

  In-depth analysis of Spring source code

  video

  Here I have compiled some fairly good video resources to share with you. For details, please reply to "spring" in the public account [Programmer Huang Xiaoxie] to view

  Blog

  Java technology warehouse "Java programmer review guide"

  https://github.com/h2pl/Java-Tutorial

  Integrate high-quality Java learning content throughout the network to help you review Java from basic to advanced systematization

  Interview Guide

  The hottest Java interview guide in the whole network, with a total of more than 200 pages, is very practical, whether it is used for review or preparing for interviews.

  Reply to "PDF" in the public account [Java Technology Rivers and Lakes] to receive it for free.

  Write at the end

  If this article is helpful to you, please don't be stingy with your "good-looking" Kazakhstan. Forwarding your circle of friends is my greatest support. Your support is my greatest encouragement.

Guess you like

Origin www.cnblogs.com/jiuq521/p/12702778.html