Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the features of Spring

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "what are the characteristics of Spring". In the operation of practical cases, many people will encounter such a dilemma. Then let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Spring understands

Spring is currently the largest framework of Java, the prototype is a doctor of music invented to interface21,Spring framework is created because of the complexity of software development, the use of Spring is not limited to server-side development. In terms of simplicity, testability and loose coupling, most Java applications can benefit from Spring. Spring is a comprehensive solution that adheres to the principle of not building new wheels. In areas where there is already a better solution, Spring never repeats its implementation, such as object persistence and OR mapping. Spring only supports existing technologies such as JDBC,Hibernate, making it easier to use without repetitive implementation. The Spring framework has many features. The official website of Spring provides the following functions for Spring:

Spring make java more simple

Spring make java more modern

Spring make java more reactive

Spring make java more productive

Spring make java more cloud-ready

In human terms, it means

Make existing technologies easier to use

Promote good programming habits.

Greatly simplify the development of applications.

Spring features are as follows:

Spring framework

The Spring framework exists in sub-modules, except for the core Spring Core Container (that is, the Spring container) is a necessary module, other modules are optional, depending on the need. There are about 20 modules.

Generally speaking, Spring is mainly divided into seven modules:

The Spring framework has many features, which consist of seven well-defined modules.

The Spring Core:Spring core, which is the most basic part of the framework, provides IOC and dependency injection features.

Spring Context:Spring context container, which is a subinterface of BeanFactory feature enhancement

Spring Web: it provides support for Web application development

Spring MVC: it aims at the realization of MVC idea in Web application.

Spring DAO: provides an abstraction layer for JDBC, which simplifies JDBC coding and makes the coding more robust.

Spring ORM: it supports integration for popular ORM frameworks, such as Spring + Hibernate, Spring + iBatis, Spring + JDO, etc.

Spring AOP:AOP, that is, aspect-oriented programming, provides a programming implementation compatible with the AOP federation.

The main Jar packages are as follows (drawing on the big picture):

Advantages of Spring

Spring provides a good framework for code organization logic and business development process specification, because if we want to implement a function, the amount of code is usually fixed, either we write it all ourselves, or we use excellent components that have been written, Spring has provided us with a variety of excellent components, the main advantages are as follows:

Support for IOC and DI

Spring is a large factory (container) that allows all object creation and dependency maintenance to be managed by Spring.

The spring factory is used to generate bean and manage the life cycle of Bean, implementing the design concept of high cohesion and low coupling.

Support for AOP programming

Spring provides aspect-oriented programming, which can easily intercept the permissions of the program, run monitoring and other functions.

Support for declarative transactions

You only need to configure to manage the transaction without manual programming, and we don't need to write any more JDBC operations that have been repeated before.

Convenient program testing

Spring provides support for Junit4, and you can easily test Spring programs through annotations.

Adhesive function

It is easy to integrate all kinds of excellent frameworks. Spring does not exclude all kinds of excellent open source frameworks, and it provides direct support for various excellent frameworks (such as Struts, Hibernate, MyBatis, Quartz, etc.).

Reduce the difficulty of using JavaEE API

Spring encapsulates some API (JDBC, JavaMail, remote calls, etc.) that are very difficult to use in JavaEE development, which greatly reduces the difficulty of these API applications.

Bean

In Spring POJO (Plain Ordinary Java Object) a simple Java object is actually a normal JavaBeans.

The bean in JavaBean means pod, and as the name suggests, the original intention of JavaBean designers is to make this class reflect the encapsulation of pods (pods seal peas inside). The JavaBean class is also a class, except that it has some special features as follows:

1. If the name of a member variable of a class is xxx, two methods can be used in the class to change or get the value of the member variable, that is, to change or get the property:

Java getXxx (), which is used to get the property xxx. SetXxx (), used to modify the property xxx.

two。 For member variables of type boolean, that is, properties of Boolean logical types, "is" is allowed instead of "get" and "set" above.

3. The access properties of methods in a class must be public.

4. If there is a constructor in the class, then the constructor is also public and has no parameters (personal feeling is not so strict).

To put it bluntly, JavaBean is nothing more than a good embodiment of object-oriented encapsulation. For example, in general, we will implement basic business units such as person, dog and other classes, with basic attributes such as age, height, weight and so on. We encapsulate these basic attributes into a whole class, and then use a logical judgment layer to deal with such a whole class.

Core thought

The two topics that Spring can never do without are IOC and AOP. Let's briefly talk about the concepts of these two words:

IOC

The IOC core of Spring is reflection + xml parsing.

The control of IOC container (Inversion of Controller) is reversed. The idea of Java is object-oriented development. An application is composed of business logic developed by a group of objects working together with each other, so how to manage these objects and make them cooperate efficiently? Abstract factory, factory method design pattern "can help us create objects, generator pattern can help us deal with the dependencies between objects, can not also accomplish these functions?" However, these require us to create other factory classes and generator classes, and we have to manage these classes, which adds to our burden. So in another way, if the object is needed, the object is automatically generated without having to create it.

For example: originally, when we were hungry, we had to buy all kinds of things to cook ourselves, but now after we have takeout, we can order food. We can tell Meituan our needs and ask them to deliver food to us. The dominant relationship here has changed. It was us, but now it is Meituan.

Spring put forward an idea: Spring is responsible for controlling the life cycle of objects and the relationship between objects. All classes will register in the Spring container to tell Spring what you are and what you need, and then Spring will give you what you want when the system is running properly, and give you what you need. The creation and destruction of all classes are controlled by spring, that is, the life cycle of an object is no longer controlled by the object that references it, but by spring. For a specific object, it used to control other objects, but now all objects are controlled by spring, so this is called control inversion, and it is difficult to see such an operation of new objects in Spring code.

AOP

AOP (Aspect Oriented Programming) is called aspect-oriented programming, which means that the method is enhanced. The core of AOP is actually dynamic agent.

Imagine, for example, writing a calculator, you need to implement the operation of addition, subtraction, multiplication and division, and write four different methods. There are two other requirements that need to be recorded before and after each operation, and digital compliance verification needs to be carried out. We have to think about how to simply achieve it.

Separate the reusable functional modules of logging and data validation, and then dynamically implant and execute the code in the appropriate place for the execution of the program. This simplifies the writing of code.

There is no reference and general logic code in the business logic code, and the business module is more concise and contains only the core business code. It realizes the code separation of business logic and general logic, facilitates maintenance and upgrade, and reduces the coupling of business logic and general logic.

Spring can do this well through configuration and without adding any additional code to the business logic code. The above approach is the AOP implemented in spring: it means aspect-oriented programming, which provides a technology to consider the program structure from another point of view to improve object-oriented programming (as opposed to OOP), and to dynamically add functions to the program without modifying the source code during compilation, loading, or running.

Human words: the popular point is to extract reusable functions, and then weave these general functions into the application at the right time. (previously, it seems that the AOP code is dynamically organized in memory to merge the section code with the business code to generate executable code.) Such as security, journaling, these are general functions, we can extract them, and then weave the code and execute them in the right place where the program is executed, so as to complete the required functions and reuse them.

History Spring FrameworkJDK1.x1.3: dynamic proxy mechanism is introduced, and the bottom layer of AOP is dynamic proxy, so Spring must be JDK 1.32.x1.4: normal upgrade 3.x5: introduce comments, the lowest version of Spring 3 is Java 5, henceforth not called 1.x directly called x4.x6: Spring 4 is an epoch-making version, starting to support functions such as Spring Boot 1.X5.x8:lambda expressions.

At present, Java development is standard: Spring Framwork 5, Spring Boot 2, JDK 8.

This is the end of the content of "what are the features of Spring"? thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report