spring @AspectJ
来源:互联网 发布:仙路烟尘 知乎 编辑:程序博客网 时间:2024/04/30 15:51
/** * 定义目标接口 * @author thinkpad * */public interface IHelloWorld2Service { public void sayHello2();}
/** * 定义目标接口实现 * @author thinkpad * */public class HelloWorld2ServiceImpl implements IHelloWorld2Service {//使用@Pointcut进行命名切入点声明@Pointcut(value="execution(* com.boventech..*.HelloWorld2ServiceImpl(..))") @Override public void sayHello2() { System.out.println("============Hello World!"); }}
//使用@Aspect将POJO声明为切面;@Aspectpublic class HelloWorldAspectAnnotation { //定义前置通知,注意这里是sayHello2//使用@Before进行前置通知声明,其中value用于定义切入点表达式或引用命名切入点@Before(value="execution(* com.boventech..*.sayHello2(..))")public void beforeAdvice() { System.out.println("===========before advice");}/*value:指定切入点表达式或命名切入点; pointcut:同样是指定切入点表达式或命名切入点,如果指定了将覆盖value属性指定的,pointcut具有高优先级;*/@AfterReturning(value="execution(* com.boventech..*.sayHello2(..))",pointcut="execution(* com.boventech..*.sayHello2(..))")public void afterFinallyAdvice() {System.out.println("===========after finally advice");}}
helloWorld2.xml
<!-- 配置文件需要使用<aop:aspectj-autoproxy/>来开启注解风格的@AspectJ支持 需要将切面注册为Bean,如“aspect”Bean--><aop:aspectj-autoproxy/><bean id="helloWorld2Service" class="com.boventech.learning.serviceImpl.HelloWorld2ServiceImpl"/> <bean id="aspect" class="com.boventech.learning.aspect.HelloWorldAspectAnnotation"/>
@Test public void testHelloworld() { ApplicationContext ctx = new ClassPathXmlApplicationContext("/helloWorld2.xml"); IHelloWorld2Service helloworldService =ctx.getBean("helloWorld2Service", IHelloWorld2Service.class); helloworldService.sayHello2(); }
0 0
- Spring + AspectJ
- spring @AspectJ
- Spring 与Aspectj集成
- spring AspectJ 基本使用
- Spring AOP + AspectJ framework
- spring中的aspectJ表达式
- Spring AOP与Aspectj
- spring mvc with aspectJ
- spring AspectJ aop学习
- Spring AspectJ注解
- spring AspectJ的Execution
- spring aop AspectJ
- Spring AOP + AspectJ annotation
- spring aspectj JoinPoint
- spring AspectJ order(顺序)
- Spring学习 AspectJ
- Spring AspectJ LTW
- Spring AOP之AspectJ
- 近降)用他注射暗捞
- 可以换规划局
- rinetd
- mac 常用快捷键
- 快乐健康么
- spring @AspectJ
- 空间邻居们
- C++11新特性:Lambda函数(匿名函数)
- maven安装及eclipse配置
- ‘lkkjhjh
- Hadoop学习路线图
- 糖尿病常识
- QTP无法录制某些控件的操作的解决方法
- 将资源映射到远程服务器