码迷,mamicode.com
首页 > 其他好文 > 详细

AOP

时间:2017-10-08 16:50:22      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:color   pid   opened   before   ofo   art   advice   object   repo   

1.前置增强

 引入一个节点
  aspectjweaver
     <!-- 技术分享https://mvnrepository.com/artifact/aspectj/aspectjweaver 
 -->
        <dependency>
            <groupId>aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
       <version>1.5.3<技术分享ersion>
        </dependency>
添加完节点后,加入xsd约束
技术分享
public interface ISomeDAO {
    public void doSome();
}





public class ISomeDAOImpl implements ISomeDAO {
    public void doSome() {
        System.out.println("国庆节");
    }
}
dao层

 

技术分享
public interface ISomeService {
    public void doSome();
}






public class ISomeServiceImpl implements ISomeService{


    public ISomeDAO getDao() {
        return dao;
    }

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

    private ISomeDAO dao;



    public void doSome() {
        dao.doSome();
    }
}
service

 

 

技术分享
public class MyBoforeAdvice implements MethodBeforeAdvice {
    public void before(Method method, Object[] objects, Object o) throws Throwable {
        System.out.println("日志记录");
    }
}
aop

 

 

技术分享
 @Test
    public void test01(){
        ApplicationContext context=new ClassPathXmlApplicationContext("applicationContextaop.xml");
        ISomeService service = (ISomeService) context.getBean("someService");
       service.doSome();
    }
测试类

 

 

 

 

 

 

 

AOP

标签:color   pid   opened   before   ofo   art   advice   object   repo   

原文地址:http://www.cnblogs.com/with-lj/p/7635282.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!