zoukankan      html  css  js  c++  java
  • SpringAOP的实现方式

    1.使用SpringAPI实现AOP

    <aop:config>
            <!-- 切入点:需要操作的目标类中的目标方法
                execution中只需要修改全类名
            -->
            <aop:pointcut id="pointcut" expression="execution(* 全类名.*(..))" />
    
            <aop:advisor advice-ref="log" pointcut-ref="pointcut"/>
            <aop:advisor advice-ref="afterLog" pointcut-ref="pointcut"/>
    </aop:config>

    2.自定义类实现AOP

    <!-- 自定义类 -->
    <bean id="diy" class="com.jay.pojo.diy"/>
        
    <aop:config>
            <!-- 切面 -->
            <aop:aspect ref="diy">
                <!-- 切入点 -->
                <aop:pointcut id="pointcut" expression="execution(* 全类名.*(..))"/>
    
                <aop:before method="before" pointcut-ref="pointcut"/>
                <aop:after method="after" pointcut-ref="pointcut"/>
            </aop:aspect>
     </aop:config>

    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文件配置
    <bean id="service" class="com.jay.service.serviceImpl"/>
    
    <!-- 注解实现的AOP类 -->
    <bean id="diy" class="com.jay.pojo.diy"/>
    
    <!-- 识别注解,自动代理 -->
    <aop:aspectj-autoproxy/>
  • 相关阅读:
    drf认证组件
    播放音频
    推荐
    makefile编写
    qt文件操作mv
    qt文件http网络下载
    为qt在window上用源代码编译库 (部分转载)
    qt线程池(转)
    crc校验
    树莓派网络配置查询
  • 原文地址:https://www.cnblogs.com/chenxi-mxj/p/11454567.html
Copyright © 2011-2022 走看看