申明一个aspect
用在一个类的前面加@Aspect来代替配置
如:
package org.xyz;
import org.aspectj.lang.annotation.Aspect;
@Aspect
public class AspectModule {
}
替换
<bean id="myAspect" class="org.xyz.AspectModule">
<!-- configure properties of aspect here as normal -->
</bean>
声明一个切入点:
import org.aspectj.lang.annotation.Pointcut;
@Pointcut("execution(* com.xyz.myapp.service.*.*(..))") // expression
private void businessService() {} // signature
申明一个businessService,且匹配该包下面的所有类的所有方法的切入点。
注意:使用该切入点的时候businessService(),不要忘记()
如果想申明一个特定的切入点,如下:
import org.aspectj.lang.annotation.Pointcut;
@Pointcut("execution(* com.tutorialspoint.Student.getName(..))")
private void getname() {}
该切入点只生效与该包下的Student的getName()这个方法。