SSM framework-Spring configuration file

1. What is the Spring framework and what are its functions?

1.1 What is Spring?

Spring is an open source application development framework used to simplify enterprise application development. The core of Spring is IOC (Inversion of Control) and AOP (Aspect Oriented Programming) .

Spring container: a core module of the spring framework for managing objects (including creation, destruction and initialization of objects). He helped complete the initialization and assembly of classes, allowing developers to break away from these underlying instantiations and dependency assembly classes, and focus on more meaningful business logic development.

1.2 The role of Spring

  1. Simplified development: Spring has made some simplifications and encapsulation of commonly used ones (for example, use spring, jdbc to access the database, no need to consider how to obtain the connection and close)
  2. Decoupling: Spring helps us manage the dependencies of objects, so that the coupling between objects is low and easy to maintain.
  3. Integration with other frameworks: Spring can integrate other frameworks. (Such as mybatis framework)

1.3 What is IOC?

IOC——: inversion of control, that is, "inversion of control", ioc is not a technology, but a design idea, an important object-oriented programming law . In Java development, IOC means giving your designed objects to the container to control, instead of directly controlling your objects in the traditional way.

What is "control" : In traditional JAVA SE programming, we create objects from the inside of the object through new, which is the creation of program control objects, and IOC has a special container (IOC container) to create objects, and the IOC container controls external resources. Obtain (including objects, files, etc.).

What is "reverse" : Traditional applications are actively controlled by ourselves in the object to directly obtain dependent objects, that is, "forward rotation". And "inversion" is the container to help us create and inject dependent objects. Objects just passively accept dependent objects. The acquisition of dependent objects is reversed.

2 Spring's two injection methods

2.1 Constructor injection

By calling the constructor of the class, the interface implementation class is passed in through the constructor variable.
Insert picture description here

Insert picture description here

Insert picture description here

2.2 setter method injection

After the container implements the bean by calling the no-parameter constructor or the no-parameter static factory method, the setter method of the bean is called, which realizes the setter-based dependency injection

Insert picture description here

Insert picture description here

Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/hzl529/article/details/102663335