傻瓜式Aop--基于xml配置前置通知

基于xml的aop配置(前置通知的使用方法)

建个maven项目 写个接口 和实现类 再写一个记录日志的类
在这里插入图片描述
建一个xml文件 约束去spring.IO搜xmlns:aop 拷贝
在这里插入图片描述
然后将实现类配置到xml里面 交给spring容器创建对象
把日志记录的类也配置进去
下面演示的还是一个前置通知使用 就是在保存用户之前调用日志方法

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xsi:schemaLocation="
        http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd">

    <!-- this is the object that will be proxied by Spring's AOP infrastructure -->

    <bean id="acServieImpl" class="com.itheima.service.impl.AcServieImpl"/>

    <!-- this is the actual advice itself
    spring 基于xml的aop配置步骤
    1.把通知bean交给spring来管理
    2.使用aop:config标签标明开始配置aop配置
    3.是使用aop:aspect标明配置切面
      id属性: 给切面指定一个唯一标识
      ref属性:指定通知类bean的id
    -->
    <bean id="Logger" class="com.itheima.log.Logger"/>

    <aop:config>
        <aop:aspect ref="Logger">
            <!--配置切入点表达式-->
            <aop:before method="printLog" pointcut="execution(public void com.itheima.service.impl.AcServieImpl.saveAccount())"></aop:before>
        </aop:aspect>
    </aop:config>

</beans>

测试结果
可以看到记录日志在保存用户操作之前执行力
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值