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();
    }
  • 相关阅读:
    quotaon
    quotacheck
    quota
    query_module
    数据库连接驱动
    PHP 开发 APP 接口 学习笔记与总结
    Java实现 LeetCode 76 最小覆盖子串
    Java实现 LeetCode 74 搜索二维矩阵
    Java实现 LeetCode 74 搜索二维矩阵
    Java实现 LeetCode 74 搜索二维矩阵
  • 原文地址:https://www.cnblogs.com/spghs/p/7637833.html
Copyright © 2011-2022 走看看