zoukankan      html  css  js  c++  java
  • MyAdvice 填充方法(在原有方法上添加方法)

    //applicationContext.xml配置文件 

    /UserServiceImp继承于UserService接口

    <!-- 1 配置目标对象-->
        <bean name="userService" class="cn.jy.service.UserServiceImp"> </bean>
        <!-- 2 配置通知对象-->
        <bean name="myAdvice" class="cn.jy.aop.MyAdvice"></bean>
        <!-- 3 配置将通知织入目标对象-->
        <aop:config>
               <!-- 配置切入点 -->
                 <aop:pointcut expression="execution(* cn.jy.service.UserServiceImp.save())" id="jy"/>
                 <aop:aspect ref="myAdvice">
                       <aop:before method="before"  pointcut-ref="jy"/>
                 </aop:aspect>
        </aop:config>

    //UserServiceImp

    package cn.jy.service;

    public class UserServiceImp implements UserService {

        public void save() {
            System.out.println("baocun");
        }
        public void delete() {
            System.out.println("delete");
        }
    }
    //UserService接口

    package cn.jy.service;

    public  interface UserService {
    void save();
    void delete();
    }

    //测试类

    package cn.jy.aop;

    import javax.annotation.Resource;

    import org.junit.Test;
    import org.junit.runner.RunWith;
    import org.springframework.test.context.ContextConfiguration;
    import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

    import cn.jy.service.UserService;
    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration("classpath:applicationContext.xml")
    public class Demo {
        @Resource(name="userService")
        private UserService u;
        @Test
        public void fun1(){
            System.out.println(u);
            u.save();
        }
    }

  • 相关阅读:
    FZU-SE-K 第一次累计得分排行榜
    OO第四次总结
    OO第二次总结
    面向对象构造与设计第一次总结
    软件工程实践2019第四次作业
    蹒跚的第一步
    学期导图
    一篇随笔
    【软工】提问回顾与个人总结
    【软工】结对项目博客
  • 原文地址:https://www.cnblogs.com/Fisherman13/p/10564851.html
Copyright © 2011-2022 走看看