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 ...
随机推荐
- IO流入门-第九章-BufferedReader_BufferedWriter复制
利用BufferedReader和BufferedWriter进行复制粘贴 import java.io.*; public class BufferedReader_BufferedWriterCo ...
- IO流入门-第一章-FileInputStream
FileInputStreamj基本用法和方法示例 import java.io.*; public class FileInputStreamTest01 { public static void ...
- DKLang Translation Editor
https://yktoo.com/en/software/dklang-traned Features Translation using a dictionary (so-called Trans ...
- LAMP兄弟连 视频教程集
电驴的资源:http://www.verycd.com/topics/2843130/?ref=msg
- socketserver模块、MySQL(数据库、数据表的操作)
一.socketserver实现并发 基于tcp的套接字,关键就是两个循环,一个链接循环,一个通信循环. socketserver模块中分两大类:server类(解决链接问题)和request类(解决 ...
- Appium自动化环境搭建(windows+Android)
开始安装: 1.首先搭建好Android开发环境(eclipse+jdk+android的sdk包+Level17或以上的版本api) 2.设置ANDROID_HOME系统变量为你的Android S ...
- flask实现获取表单并执行shell
1.一个HTML form input和一个button提供给用户输入 2.使用flask的request获取用户输入的文件名 3.判断输入异常 4.执行shell命令touch aa.txt 并返回 ...
- getElementsByClassName - 兼容详细介绍
概述 JavaScript中getElementsByClassName()方法IE8及以下不支持.本文通过使用正则表达式实 现1个兼容方案. 本文内容分为3个部分. 浏览器原生getElements ...
- 吴超老师课程---Hadoop的伪分布安装
1.1 设置ip地址 执行命令 service network restart 验证: ifconfig1.2 关闭防火墙 执行命令 service ip ...
- python16_day06【类、RE模块、subprocess模块、xml模块、shelve模块】
一.shelve模块 import shelve # 基于pickle模块, d = shelve.open('shelve_test') class Test(object): def __init ...