Principles of spring ioc aop
Spring ioc aop principle spring IoC container is the core of spring, and spring AOP is an important part of spring framework. In traditional programming, when the caller needs the assistance of the caller, the caller usually creates the instance of the caller. However, the creation of callers in spring is no longer done by the callers, so the control reversal (IoC) is implemented. The creation of the called instance is usually done by the spring container and then injected into the caller, therefore, it is also called dependency injection (DI). Dependency injection and control inversion are the same concept. Aspect-oriented programming (AOP) is to consider the program structure from another perspective and improve Object-Oriented Programming (OOP) by analyzing the focus of the program structure ). OOP splits an application into objects at various layers, while AOP splits the program into multiple sections. Spring AOP only implements method-level connection points. In J2EE applications, it is sufficient for AOP to intercept methods. In spring, in the future, IoC will make it easy to use robust and flexible Enterprise Services. spring AOP should be used to establish a connection between IoC and Enterprise Services. IOC: Control inversion is also called dependency injection. The factory mode is used to send objects to container management. You only need to configure the corresponding bean in the spring configuration file and SET related properties, let spring containers generate class instance objects and management objects. When the spring container is started, spring initializes all the beans you configured in the configuration file, and when you need to call the bean, assign the beans it has initialized to the classes that you need to call these beans (assuming the Class Name Is A). The allocation method is to call the setter method of a for injection, you don't need to create new beans in. Note: If you have the necessary conditions during the interview, you can draw a picture. AOP: Aspect-Oriented Programming. (Aspect-Oriented Programming) AOP can be said to supplement and improve OOP. OOP introduces concepts such as encapsulation, inheritance, and Polymorphism to establish an object hierarchy to simulate a set of public behaviors. When we need to introduce public behavior to scattered objects, OOP seems powerless. That is to say, OOP allows you to define the relationship from top to bottom, but it is not suitable for defining the relationship from left to right. For example, log function. Log Code is often horizontally distributed across all object layers, but it has nothing to do with the core functions of the objects it spreads. In OOP design, it leads to a lot of code duplication, which is not conducive to the reuse of each module. Encapsulate the cross-business logic (such as security, logs, and transactions) in a program into a plane and inject it into the target object (specific business logic. The technology for Implementing AOP is mainly divided into two categories: one is to use dynamic proxy technology, and use the method of intercepting messages to describe the message to replace the execution of the original object behavior; the second is to use static weaving to introduce specific syntax to create "aspect", so that the compiler can weave "aspect" code during compilation. for example, if you want to add a print 'hello' function to all the classes in your biz layer, you can use the aop idea. first, you write a class to write a class method. After the method is implemented, print 'hao', and then the Ioc class ref = "biz. * "to inject each class.