zoukankan      html  css  js  c++  java
  • Aop小列子

    //引入节点
    <!-- https://mvnrepository.com/artifact/aspectj/aspectjweaver-->
    <dependency>
    <groupId>aspectj</groupId>
    <artifactId>aspectjweaver</artifactId>
    <version>1.5.3</version>
    </dependency>
    //接口dao
    public interface ISomeDAO {
    public void doSome();
    }

    //实现接口Dao
    public class SomeDaoImpl implements ISomeDAO {
    public void doSome() {
    System.out.println("国庆节快乐");
    }
    }
    Service接口
    public interface ISomeService {
    public void doSome();
    }

    //service接口实现
    public class SomeServiceImpl implements  ISomeService {
    private ISomeDAO dao;

    public ISomeDAO getDao() {
    return dao;
    }

    public void setDao(ISomeDAO dao) {
    this.dao = dao;
    }

    public void doSome() {

    dao.doSome();
    }
    }
    xml配置


      //前置增强<bean id="beforeAdvice" class="cn.happy.day03.aop.MyBeforeAdvice">
    //后置增强<bean id="afterAvice" class="cn.happy.day03.aop.MyafterAdvice">

    </bean>
    <aop:config>
    <aop:pointcut id="mypointcut" expression="execution(* *..dao.*.*(..))"></aop:pointcut>
    <aop:advisor advice-ref="afterAvice" pointcut-ref="mypointcut"></aop:advisor>
    </aop:config>

    //单测
        public void test01(){
    ApplicationContext context=new ClassPathXmlApplicationContext("applicationContextday03.xml");
    /*HappyServices service=(HappyServices)context.getBean("service");
    service.work();
    System.out.println(service);*/
    ISomeService service=(ISomeService)context.getBean("someService");
    service.doSome();
    }
  • 相关阅读:
    面试题
    iOS 两种方法实现左右滑动出现侧边菜单栏 slide view
    进程、线程、多线程相关总结
    iOS开发
    播放 视频
    delphi控件属性大全-详解-简介
    Cxgrid获取选中行列,排序规则,当前正在编辑的单元格内的值
    FastReport 使用说明
    delphi的取整函数round、trunc、ceil和floor
    cxGrid 速度
  • 原文地址:https://www.cnblogs.com/spghs/p/7637833.html
Copyright © 2011-2022 走看看