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/>
  • 相关阅读:
    日常小算法
    美化type="file"控件
    流文件_从网络中获取文件
    Kibana配置安装
    JDK安装
    Node.js安装windows环境
    RabbitMQ高可用
    RabbitMQ实例C#
    RabbitMQ基础命令rabbitmqctl
    RabbitMQ配置
  • 原文地址:https://www.cnblogs.com/chenxi-mxj/p/11454567.html
Copyright © 2011-2022 走看看