spring3: schema的aop与Aspectj的aop的区别
schema的aop如下:
接口:
package chapter6.service;
public interface IHelloAroundService {
public void sayAround(String param);
}
接口的实现:
package chapter6.service.impl;
import chapter6.service.IHelloAroundService;
public class HelloAroundService implements IHelloAroundService {
public void sayAround(String param) {
// TODO Auto-generated method stub
System.out.println("========= say around param: " + param);
} }
aop程序
package chapter6.aop;
import org.aspectj.lang.ProceedingJoinPoint;
public class HelloAroundAspect {
public Object sayAroundAdvice(ProceedingJoinPoint pjp) throws Throwable
{
System.out.println("============= before around advice");
Object retVal = pjp.proceed(new Object[] {"replace"});
System.out.println("============= after around advice");
return retVal;
} }
配置文件说明:
<!-- 接口的实现 -->
<bean id="HelloAroundService" class="chapter6.service.impl.HelloAroundService" />
<!-- 切面程序 -->
<bean id="aspect" class="chapter6.aop.HelloAroundAspect" />
<aop:config>
<!-- 定义插入点 -->
<aop:pointcut expression="execution(* chapter6..*.sayAround(..))" id="pointcut"/>
<!-- 通知 -->
<aop:aspect ref="aspect">
<aop:around
pointcut-ref="pointcut"
method="sayAroundAdvice"/>
</aop:aspect>
</aop:config>
测试程序大同小异不做展示
Aspectj的aop如下:
接口 :
package chapter1.server;
public interface IHelloService { public void sayAdvisorBefore(String param) ;
}
接口实现:
package chapter1.service.impl;
import chapter1.server.IHelloService;
public class HelloService implements IHelloService {
public void sayAdvisorBefore(String param) {
// TODO Auto-generated method stub
System.out.println("============say " + param);
}
}
aop程序:
package chapter1.aop; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut; @Aspect
public class HelloAspect { //定义切入点
@Pointcut(value="execution(* chapter1..*.sayAdvisorBefore(java.lang.String)) && args(param)", argNames = "param")
public void beforePointcut(String param) {} //定义通知
@Before(value = "beforePointcut(param)", argNames = "param")
public void beforeAdvice(String param) {
System.out.println("===========before advice param:" + param);
}
}
配置文件:
<!-- 启动对Aspectj的支持 -->
<aop:aspectj-autoproxy/>
<bean id="helloService" class="chapter1.service.impl.HelloService" />
<bean id="aspect" class="chapter1.aop.HelloAspect"/>
测试程序:
@Test
public void testAspectj()
{
ApplicationContext context = new ClassPathXmlApplicationContext("chapter1/aspectj.xml");
IHelloService hello = context.getBean("helloService", IHelloService.class);
hello.sayAdvisorBefore("before");
}
结果:
===========before advice param:before
============say before
spring3: schema的aop与Aspectj的aop的区别的更多相关文章
- spring3: 切面及通知实例 Aspectj的aop
1.前置通知 接口: package chapter1.server; public interface IHelloService { public void sayAdvisorBefore(St ...
- spring9——AOP之AspectJ对AOP的实现
从上述的实验中可以看出BeanNameAutoProxyCreator对于AOP的实现已经和完美了,但是还有两点不足之处: 1,对于切面的实现比较麻烦,既不同类型的通知切面要实现不同的接口,而且一个切 ...
- Spring -- aop, 用Aspectj进行AOP开发
1. 概要 添加类库:aspectjrt.jar和aspectjweaver.jar 添加aop schema. 定义xml元素:<aop:aspectj-autoproxy> 编写jav ...
- 第三章 AOP 基于@AspectJ的AOP
在前面,我们分别使用Pointcut.Advice.Advisor接口来描述切点.增强.切面.而现在我们使用@AdpectJ注解来描述. 在下面的例子中,我们是使用Spring自动扫描和管理Bean. ...
- Spring框架(6)---AspectJ实现AOP
AspectJ实现AOP 上一篇文章Spring框架(4)---AOP讲解铺垫,讲了一些基础AOP理解性的东西,那么这篇文章真正开始讲解AOP 通过AspectJ实现AOP要比普通的实现Aop要方便的 ...
- 比较 Spring AOP 与 AspectJ
本文翻译自博客Comparing Spring AOP and AspectJ(转载:https://juejin.im/post/5a695b3cf265da3e47449471) 介绍 如今有多个 ...
- 开涛spring3(6.4) - AOP 之 6.4 基于@AspectJ的AOP
Spring除了支持Schema方式配置AOP,还支持注解方式:使用@AspectJ风格的切面声明. 6.4.1 启用对@AspectJ的支持 Spring默认不支持@AspectJ风格的切面声明, ...
- 基于@AspectJ和schema的aop(二)---@AspectJ基础语法
@AspectJ使用jdk5.0和正规的AspectJ切点表达式描述切面, 由于spring只支持方法的连接点,所以Spring只支持部分AspectJ的切点语言. 1.切点表达式函数 AspectJ ...
- Spring @AspectJ 实现AOP 入门例子(转)
AOP的作用这里就不再作说明了,下面开始讲解一个很简单的入门级例子. 引用一个猴子偷桃,守护者守护果园抓住猴子的小情节. 1.猴子偷桃类(普通类): package com.samter.common ...
随机推荐
- dev EditMask 设置方法
官方帮助地址: https://documentation.devexpress.com/WindowsForms/583/Controls-and-Libraries/Editors-and-Sim ...
- 解决URL地址中的中文乱码问题的办法
解决URL地址中的中文乱码问题的办法 引言: 在Restful类的服务设计中,经常会碰到需要在URL地址中使用中文作为的参数的情况,这种情况下,一般都需要正确的设置和编码中文字符信息.乱码问题就此产生 ...
- 笔记-django学习链接
form表单学习 https://www.cnblogs.com/weiman3389/p/6225075.html python字符串replace()方法 https://www.cnblogs. ...
- 编程算法 - 全然背包问题 代码(C)
全然背包问题 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 有n个重量和价值分别为w,v的物品, 从这些物品中挑选出总重量不超过W的物品, 求 ...
- 关闭SourceInsight的大括号自动缩进
使用Source Insight可以很好的管理项目代码,也非常便于阅读.但是,在使用Source Insight书写C语言代码时,会发现这样的问题,键入大括号之后,它会自动缩进一个制表符,这种处理跟我 ...
- 基于WinIO 3.0实现驱动级键盘模拟输入
基于WinIO 3.0实现驱动级键盘模拟输入 一个业务场景需要使用驱动级的键盘模拟,折腾了2天,总结一下,为后人节省时间. 限制条件: 1.需要真实PC机,虚拟机不行 2.仅支持PS/2 键盘(指外接 ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) E. Tree Folding
地址:http://codeforces.com/contest/765/problem/E 题目: E. Tree Folding time limit per test 2 seconds mem ...
- CodeForces - 920F SUM and REPLACE (线段树)
题意:给N个数M次操作,(1<=N,M<=3e5, 1<=ai<=1e6),1是使[L,R]中的每个元素变成其因子的个数之和:2是求[L,R]区间之和 分析:看上去就很线段树的 ...
- Python面试题之Python对象反射、类反射、模块反射
python面向对象中的反射:通过字符串的形式操作对象相关的属性.python中的一切事物都是对象(都可以使用反射) 一.getattr 对象获取 class Manager: role = &quo ...
- [国家集训队] calc(动规+拉格朗日插值法)
题目 P4463 [国家集训队] calc 集训队的题目真是做不动呀\(\%>\_<\%\) 朴素方程 设\(f_{i,j}\)为前\(i\)个数值域\([1,j]\),且序列递增的总贡献 ...