java interview - spring ioc and aop

The interviewer asked this question basically to know if you understand the basic concepts of aop and ioc, as well as the general implementation mechanism, etc. Therefore, when we answer this question, the prime minister should answer the concept, followed by the application scenario and finally implement it under the answer The way is basically ok

 

1 Concept:

First, let’s talk about aop, aop is a concept equivalent to oop, oop is object-oriented programming and aop is aspect-oriented programming. In essence, both oop and aop are programming ideas. oop focuses on the direct calling relationship of objects and the relationship between modules. The direct business connection between modules is a vertical behavior; aop is more concerned with the problem (business invocation and logic) of the object behavior between modules. We can extract these common processing logic as a surface, which is a horizontal behavior.

 

ioc control inversion/dependency injection, mainly the decoupling of objects, handing over the control of objects to the container, including the creation and destruction of objects, etc., we only need to focus on business logic, the important thing is that ioc is a kind of idea!

 

How the ioc container manages beans:

      1>beanFactory ; 2>applicationContext; 注意 applicationContext extends beanFactory!

 

2 Applications:

The main role of aop is to monitor functions/business logic calls, exceptions and other issues, and it is actually applied to cross-cutting concerns such as things, security and logs!

 

Implementation of 3aop:

Use jdk's dynamic proxy and cglib Note: For classes with interfaces, aop uses jdk's dynamic proxy, and for classes without interfaces or abstract classes, use cglib. Although cglib can be proxied, its complexity and efficiency are low, and no final method!

 

 

 

 

 

 

Guess you like

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