1. What is Spring? 3. What is the difference between Spring and springMVC

1. What is Spring?

What is Spring? Is a container framework according to the Internet, what is the development framework, is a.. . Until we really understand Spring, these so-called theories can be as dull and hard to understand. So now let’s take an example of A fully independent r&d factory, workshop A, which was given the task of producing an Audi A6, and that had to be programmed

1A6 a6=new A6();

Copy the code

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

1LunTai t1=new LunTail();

2LunTai t2=new LunTail();

3LunTai t3=new LunTail();

4LunTai t4=new LunTail();

Copy the code

The tires are made of rubber, so

1Xiangjiao xj=new Xiangjiao();

Copy the code

… . Therefore, you will find that 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 specializing in the production of tires and other parts, B sells parts to factory A and the two factories hit it off: Factory B produces parts for factory A, which becomes: when factory A needs parts, it can directly purchase from factory B

1// Purchase tires

2LunTai t1=B.getBean("LunTai");

3// Buy glass

4BoLi b1=B.getBean("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

1ApplicationContext 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

1A6 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.

Find this article helpful? Please share it with more people

Focus on “programming without boundaries” and improve your skills