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();
    }
  • 相关阅读:
    Phone List(字典树)
    Dating with girls(1)(二分+map+set)
    Color the ball(树状数组+线段树+二分)
    python模块导入总结
    Python爬虫之定时抢购淘宝商品
    Celery多队列配置
    python垃圾回收机制
    python变量、对象和引用你真的明白了吗
    使用 supervisor 管理 Celery 服务
    Supervisor的作用与配置
  • 原文地址:https://www.cnblogs.com/spghs/p/7637833.html
Copyright © 2011-2022 走看看