Inject interceptor


Inject interceptor refers to the interceptor passed in using parameters when using the enhance or duang method to enhance. Inject can apply AOP to the target completely non-invasively.

If the target that needs to be enhanced is in the jar package, the Before annotation cannot be used to configure the interceptor. At this time, the Inject interceptor can be used to enhance the target in the jar package. The following is an example of an Inject interceptor:

public void injectDemo() {
	// 为enhance方法传入的拦截器称为Inject拦截器,下面代码中的Tx称为Inject拦截器 OrderService service = Enhancer.enhance(OrderService.class, 		Tx.class); service.payment(…);
}


Enhance.enhance() method in the above code The second parameter Tx.class is called the Inject interceptor. Using this method, you can perform AOP enhancement on the target completely non-invasively.



Inject interceptor is related to the Global, Class, and Method levels mentioned earlier Interceptors are concepts on the same level. Like Class-level interceptors, Inject interceptors will intercept all methods in the enhanced target. The Inject interceptor can be thought of as a Class-level interceptor, but the execution order is before the Class-level interceptor.