首页 | 联系我们 | 叶凡网络官方QQ群:323842844
游客,欢迎您! 请登录 免费注册 忘记密码
您所在的位置:首页 > 开发语言 > Java开发 > 正文

AOP中的arround advice

作者:cocomyyz 来源: 日期:2013-07-25 02:49:21 人气:52 加入收藏 评论:0 标签:java

LogBean.java


package com.brj.spring.aop.arroundadvice;

import org.aspectj.lang.ProceedingJoinPoint;

public class LogBean {

public Object arroundLog(ProceedingJoinPoint joinPoint) throws Throwable{
  System.out.println("before..........");
  Object obj = joinPoint.proceed();
  System.out.println("after...........");
  return null;
}

}


TargetBean.java


package com.brj.spring.aop.arroundadvice;

public class TargetBean {

public void printInformation(){
  System.out.println("targetBean is worked...");
}

}


Test.java


package com.brj.spring.aop.arroundadvice;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Test {


public static void main(String[] args) {
  ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
  TargetBean proxyT = (TargetBean) ac.getBean("targetBean");
  proxyT.printInformation();

}

}


applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

<bean id="targetBean"
  class="com.brj.spring.aop.arroundadvice.TargetBean">
</bean>

<bean id="logBean"
  class="com.brj.spring.aop.arroundadvice.LogBean">
</bean>

<aop:config>
  <aop:pointcut id="logPoint"
   expression="execution(public * *(..)) and ! execution(* com.brj.spring.aop.arroundadvice.LogBean.*(..))" />

  <aop:aspect id="logAspect" ref="logBean">
   <aop:around pointcut-ref="logPoint" method="arroundLog" />
  </aop:aspect>
</aop:config>
</beans>


本文网址:http://www.mingyangnet.com/html/java/148.html
读完这篇文章后,您心情如何?
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
  • 0
更多>>网友评论
发表评论
编辑推荐
  • 没有资料