Three core learning of spring

Three core learning of spring

spring是一个轻型容器(light-weight Container),其核心是Bean工厂(Bean Factory),用以构造我们所需要的M(Model)
  • 1
  • 2

IOC (Inversion of Control)

Below are several expressions for this understanding.

  • When an object A depends on another object B, it must go to new by itself. This is the use of a highly coupled IOC container. 
    For example, A is used a lot in B, and when A changes a lot, a lot of code needs to be modified in B.
  • The popular understanding is: usually we create a new instance, the control of this instance is our programmer, and inversion of control means that the work of the new instance is not done by our programmers, but is done by the spring container.
  • For an interface, we may write multiple implementation classes. If the object of the implementation class is created in the code or in the program, when we want to replace the implementation class (using other implementation classes), we need to change the code.
  • A usage instance 
    passes the IOC function of spring. In the xml configuration file, the implementation class of the interface is given a name "XXX". When the object is created in the code, it is created in the following way: 

DI (Dependency Injection, Dependency Injection)

首先应该明白两个问题:1,谁依赖谁;2,谁注入,注入什么?
  • 1
  • 2
  • Using the configuration information of xml, no specific new java objects are needed in the client code. The creation of java objects and the assignment of elements in objects can be handled by xml (spring).
  • Answer the first two questions in the article: 1. In the client code, the creation of specific objects depends on the xml file (spring, that is, the IOC container); 2. It is the injection of the IOC container. During the runtime, according to the configuration information of the xml, the specific object is injected The object is injected into the corresponding bean.

JavaBean: In order to write a class that is convenient for others to use, it is stipulated that there must be a constructor with zero parameters, and the get/set method should be used at the same time to hide internal details and facilitate use and subsequent code updates.


  • For a JavaBean, in order to use it, you first need to new an object, and then you need to call the set method and assign a value. The connections between the codes become larger, and the encapsulated features gradually become smaller. This is troublesome when modifying the code. There are piles of changes, especially in the process of development by different teams, and the impact of code changes is huge.
  • Through inversion of control (IOC) and dependency injection, the same object of new is given a nickname in the xml file. In this way, only the specific path of the class corresponding to the nickname needs to be changed in the xml file. . No need to replace .java files one by one.
  • When using the set method to pass the value, if you fill in the specific attribute value, it will be more troublesome to change. It is more convenient to change the value through Spring.

Note: There seem to be many ways to pass the value of the set method and the specific operation methods. The specific understanding is not enough. It requires actual coding and learning through professional book systems. 2017.1.3

Aspect Oriented AOP

可以通过预编译方式和运行期动态代理实现在不修改源代码的情况下给程序动态统一添加功能的一种技术。
  • 1
  • 2
  • Divide the code of logging, performance statistics, security control, transaction processing, exception handling, etc. from the business logic code
Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission. https://blog.csdn.net/yks0527/article/details/54093490

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325207567&siteId=291194637