SpringAOP的实现方式

1.使用SpringAPI实现AOP


        
        "pointcut" expression="execution(* 全类名.*(..))" />

        ref="log" pointcut-ref="pointcut"/>
        ref="afterLog" pointcut-ref="pointcut"/>

2.自定义类实现AOP


"diy" class="com.jay.pojo.diy"/>
    

        
        ref="diy">
            
            "pointcut" expression="execution(* 全类名.*(..))"/>

            "before" pointcut-ref="pointcut"/>
            "after" pointcut-ref="pointcut"/>
        
 

3.使用注解实现AOP

注解实现类
//必须写切面注解,否则无法切入
@Aspect
public class diy {

    @Before("execution(* com.jay.service.serviceImpl.*(..))")
    public void before(){
        System.out.println("这是before方法");
    }

    @After("execution(* com.jay.service.serviceImpl.*(..))")
    public void after(){
        System.out.println("这是after方法");
    }
}
XML文件配置
class="com.jay.service.serviceImpl"/>


class="com.jay.pojo.diy"/>


 

你可能感兴趣的:(SpringAOP的实现方式)