1 |
|
切面:切点的容器,使用@Aspect定义
切点(PointCut):拦截规则,一般分为基于方法(execution)或基于注解(@annotation),可以被复用
建言(Advice):拦截植入的时机及动作,@Before、@After、@Around、@AfterReturing和@AfterThrowing,需指定切点,可以直接基于方法或基于PointCut指定
连接点(JoinPoint):符合拦截规则的每一个被拦截处
Enables support for handling components marked with AspectJ’s @Aspect
annotation, similar to functionality found in Spring’s <aop:aspectj-autoproxy>
XML element. To be used on @Configuration
classes as follows:
1 |
|
Where FooService is a typical POJO component and MyAspect is an @Aspect-style aspect:
1 |
|
1 |
|
In the scenario above, @EnableAspectJAutoProxy ensures that MyAspect will be properly processed and that FooService will be proxied mixing in the advice that it contributes. Users can control the type of proxy that gets created for FooService
using the proxyTargetClass()
attribute. The following enables CGLIB-style ‘subclass’ proxies as opposed to the default interface-based JDK proxy approach.
1 |
|
Note that @Aspect
beans may be component-scanned like any other. Simply mark the aspect with both @Aspect
and @Component
:
1 |
|
Then use the @ComponentScan annotation to pick both up:
1 |
|