Sources: in this paper, from programming unbounded, https://mp.weixin.qq.com/s/Wmt6QcMsFY2sHs-bm2X3og, piece please support! Thank you for reading.

Read the words: 3575 | 9 minutes to read

Abstract

1. What is Spring?

2. What does Spring do

3. Differences between Spring and Spring MVC

4. Spring Framework modules

1. What is Spring?

What is Spring?

It’s a container framework, it’s a development framework, it’s a…

Until we really understand Spring, these so-called theories can be as dull and hard to understand.

Now let’s take a chestnut

Fully independent research and development factory A workshop received the task, to produce an Audi A6, that in the programming

1   A6 a6=new A6();Copy the code

But the A6 has a lot of parts, like it needs four tires, so it does

1  LunTai t1=new LunTail();
2  LunTai t2=new LunTail();
3  LunTai t3=new LunTail();
4  LunTai t4=new LunTail();Copy the code

The tires are made of rubber, so

1  Xiangjiao xj=new Xiangjiao();Copy the code

So, you will find, to build a car requires layers of nested components production logic, makes the factory needs to be, and should display and every step needs to wait for the previous steps to complete, this will cause the inefficient factories, in the Java programming ideas, this is called the highly coupled.

What about factories to improve efficiency?

At this time, there is A factory B specializing in tires and other parts to sell parts to factory A

The two factories hit it off:

B factory produces spare parts for A factory

This becomes:

When factory A needs parts, it can purchase directly from factory B

1 LunTai t1= b.goetbean ("LunTai"); 4 BoLi b1= b.gettbean ("BoLi");Copy the code

It can be seen that factory A relies on parts from factory B. In Spring’s mind, it is called dependency, that is, Spring is A container (Factory B), and our project (Factory A) needs any object from the container, regardless of how it came from.

Now let’s go back to the theory:

Spring is a container framework for holding Javabeans (Java objects), and the mid-tier framework (universal glue) can serve as a link, such as gluing Struts and Hibernate together. In simple terms, Spring is a lightweight Inversion of Control (IoC) and AOP oriented container framework.

This is easy to understand: Spring is a Java development framework, and its core is the Spring container, which manages the management of Java components in Spring

1  ApplicationContext ctx  = new ClassPathXmlApplicationContext("spring-bean.xml")Copy the code

The above code instantiates a container and loads all of the bean components in spring-bean.xml. When the business needs an object, we don’t need to new an object but get it directly from the container, as in

1  A6 a=ctx.getBean("A6Bean");Copy the code

2. What does Spring do?

  1. Create and assemble dependencies between objects based on configuration files.

  2. As a complement to OOP (object-oriented programming), Spring’s AOP (aspect oriented programming) decouples business code.

  3. Transaction management no longer needs to be implemented in business code, but is managed by Spring.

  4. Fast and seamless integration with other frameworks.

3. Differences between Spring and Spring MVC

Spring is a container, and SpringMVC is a Web framework that is a module of Spring

4. Spring Framework modules

  1. Spring container: Provides the basic functionality of the Spring framework. The main component of the core container is the BeanFactory, which is an implementation of the factory pattern. The BeanFactory uses an inversion of Control (IOC) pattern to separate the application’s configuration and dependency specifications from the actual application code.

  2. Spring Context: The Spring context is a configuration file that provides context information to the Spring framework. The Spring context includes enterprise services, such as JNDI, EJB, E-mail, internationalization, validation, and scheduling capabilities.

  3. Spring AOP: Faceted programming.

  4. Spring DAO: The JDBC DAO abstraction layer provides a meaningful exception hierarchy that can be used to manage exception handling and error messages thrown by different database vendors. The exception hierarchy simplifies error handling and greatly reduces the amount of exception code you need to write (such as opening and closing connections). Spring DAO’s JDBC-oriented exceptions follow a common DAO exception hierarchy.

  5. Spring ORM: The Spring framework inserts several ORM frameworks to provide ORM’s object-relational tools, including JDO, Hibernate, and iBatis SQL Map. All follow Spring’s common transaction and DAO exception hierarchies.

  6. Spring Web: The Web context module builds on the application context module and provides the context for Web-based applications. So, the Spring framework supports integration with Jakarta Struts. The Web module also simplifies handling multi-part requests and binding request parameters to domain objects.

  7. Spring MVC: A Web framework provided by Spring.

That’s all for today’s sharing. Thank you!

Editor: IT big guy said, reprint please indicate copyright and source