spring development
1. Spring 1.x era
In the Spring 1.x era, beans are configured through xml files. As the project continues to expand, xml configuration needs to be divided into different configuration files, and frequent switching between java classes and xml configuration files is required.
2. Spring 2.x era
With the annotation support brought by JDK 1.5, Spring 2.x can use annotations to declare and inject Bean, which greatly reduces the xml configuration file, and also greatly simplifies the development of the project.
So, the question is, should I use XML or annotations?
3. The annotation is still XML
In the early version of spring, because the JDK did not support annotations at that time, it could only use XML configuration. Soon, as the JDK was upgraded to JDK5, it added new features of annotations, so that annotations were widely used , So there are two schools in Spring, one is using XML and the other is using annotations. In order to simplify development, annotations have also been introduced in versions after spring 2.X, but only a small amount of annotations, such as @Component @Service , But the function is still not powerful, so for the development of spring, in most cases, XML is mainly used. With the increase of annotations, especially after Servlet3.0, the WEB container can be separated from the deployment of web.xml and used in WEB container It can be developed based on annotations , and the annotation functions for spring3 and spring4 are becoming more and more powerful. The less reliance on XML is, it can be completely separated from XML by 4.0, so the use of annotation development in spring has occupied the mainstream position in recent years. The popularity of microservices, more and more companies require rapid development, so spring Boot is more prosperous.
1. The basic configuration of the application uses xml, such as: data source, resource file, etc .;
2. Annotations for business development, such as: injecting beans into Service, etc .;
4,Spring3.x到Spring4.x
Java configuration has been provided since Spring 3.x. Using Java configuration can better understand the beans you configure. Now we are in this era, and both Spring 4.x and Springboot recommend the use of java configuration.
5. The advantages of SpringBoot
1. Create an independent spring application.
2. Embedded tomcat jetty or undertow do not need to deploy WAR file.
3. Allow Maven to get the starter as needed
4. Use automatic configuration spring as much as possible
5. Provide production-ready functions, such as indicators, health checks and external configuration
6. There is absolutely no code generation, no requirement for XML configuration
Introduction to springboot and microservices
1. Introduction to springboot
Spring Boot is a new framework provided by the Pivotal team. Its design purpose is to simplify the initial construction and development process of new Spring applications.
The framework uses a specific way to configure, so that developers no longer need to define a sample configuration.
In this way, Spring Boot is committed to becoming a leader in the rapid development of rapid application development (rapidapplication development).
2. Why use springboot
Create a standalone Spring application
Embedded Tomcat, no need to deploy WAR file
Simplify Maven configuration
Automatically configure Spring
Provide production-ready features such as indicators, health checks and external configuration
Out of the box, there is no code generation and no XML configuration.
Natural integration with cloud computing
3. Features understanding
Provide a faster introductory experience for Spring-based development
Out of the box, there is no code generation and no XML configuration. You can also modify the default values to meet specific needs.
Provide some common non-functional features in large projects, such as embedded servers, security, indicators, health detection, external configuration, etc.
Spring Boot does not enhance the functionality of Spring, but provides a way to quickly use Spring.
4. Traditional development model
All functions are packaged in a WAR package , basically no external dependencies (except for containers) , deployed in a JEE container (Tomcat, JBoss, WebLogic), including all logic such as DO / DAO, Service, UI.
advantage:
①Simple development and centralized management
② Basically will not repeat development
③The functions are all local, no distributed management and call consumption
Disadvantages:
1. Low efficiency: developers are changing code in the same project, waiting for each other, and conflicts are constant
2. Difficult to maintain: code functions and functions are coupled together, the newcomer does not know how to start
3. Inflexible: The construction time is long, and any small changes will require reconstruction of the entire project, which takes time
4. Poor stability: A small problem may cause the entire application to hang
5. Insufficient scalability: unable to meet business requirements under high concurrency
6. The performance requirements of the server should be uniform and high
5. Microservice development
Microservices: architectural style (service micro)
Microservices refers to the development of a single small but business function service. Each service has its own processing and lightweight communication mechanism, which can be deployed on a single or multiple servers. Service-oriented architecture with a certain bounded context
Purpose: Effectively split applications to achieve agile development and deployment
advantage
1. Each microservice is small, so that it can focus on a specified business function or business requirement
2. The microservice can be developed by a small team, and this small team can be completed by 2-5 people
3. Microservices are loosely coupled, and are functional and meaningful services, independent in the development or deployment phase
4. Microservices can be developed in different languages
5. Microservices can be deployed on low-end and mid-range servers
6. It is easy to integrate with third parties
7. Each service has its own storage capacity, a separate library, or a unified library
Disadvantages
1. Microservices will bring too many operations
2. Can have double the effort
4. Distributed systems can be complex and difficult to manage
5. Difficult distribution and deployment
6. As the number of services increases, the management complexity increases