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的区别的更多相关文章

  1. spring3: 切面及通知实例 Aspectj的aop

    1.前置通知 接口: package chapter1.server; public interface IHelloService { public void sayAdvisorBefore(St ...

  2. spring9——AOP之AspectJ对AOP的实现

    从上述的实验中可以看出BeanNameAutoProxyCreator对于AOP的实现已经和完美了,但是还有两点不足之处: 1,对于切面的实现比较麻烦,既不同类型的通知切面要实现不同的接口,而且一个切 ...

  3. Spring -- aop, 用Aspectj进行AOP开发

    1. 概要 添加类库:aspectjrt.jar和aspectjweaver.jar 添加aop schema. 定义xml元素:<aop:aspectj-autoproxy> 编写jav ...

  4. 第三章 AOP 基于@AspectJ的AOP

    在前面,我们分别使用Pointcut.Advice.Advisor接口来描述切点.增强.切面.而现在我们使用@AdpectJ注解来描述. 在下面的例子中,我们是使用Spring自动扫描和管理Bean. ...

  5. Spring框架(6)---AspectJ实现AOP

    AspectJ实现AOP 上一篇文章Spring框架(4)---AOP讲解铺垫,讲了一些基础AOP理解性的东西,那么这篇文章真正开始讲解AOP 通过AspectJ实现AOP要比普通的实现Aop要方便的 ...

  6. 比较 Spring AOP 与 AspectJ

    本文翻译自博客Comparing Spring AOP and AspectJ(转载:https://juejin.im/post/5a695b3cf265da3e47449471) 介绍 如今有多个 ...

  7. 开涛spring3(6.4) - AOP 之 6.4 基于@AspectJ的AOP

    Spring除了支持Schema方式配置AOP,还支持注解方式:使用@AspectJ风格的切面声明. 6.4.1  启用对@AspectJ的支持 Spring默认不支持@AspectJ风格的切面声明, ...

  8. 基于@AspectJ和schema的aop(二)---@AspectJ基础语法

    @AspectJ使用jdk5.0和正规的AspectJ切点表达式描述切面, 由于spring只支持方法的连接点,所以Spring只支持部分AspectJ的切点语言. 1.切点表达式函数 AspectJ ...

  9. Spring @AspectJ 实现AOP 入门例子(转)

    AOP的作用这里就不再作说明了,下面开始讲解一个很简单的入门级例子. 引用一个猴子偷桃,守护者守护果园抓住猴子的小情节. 1.猴子偷桃类(普通类): package com.samter.common ...

随机推荐

  1. openssl update--centos 6.5

    cd /usr/local/src #wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz #tar -zxvf openssl-1.0.1 ...

  2. Xcode 编译静态库

    有时候,我们需要将一部分经常用到的代码提取出来用来复用,或者说需要用到c++的代码的时候,可以通过编译成静态库的方式来使用.本文中使用的Xcode版本是8.3,静态库制作过程和其他版本基本一样,可能出 ...

  3. <2014 05 09> Lucida:我的算法学习之路

    [转载] 我的算法学习之路 关于 严格来说,本文题目应该是我的数据结构和算法学习之路,但这个写法实在太绕口——况且CS中的算法往往暗指数据结构和算法(例如算法导论指的实际上是数据结构和算法导论),所以 ...

  4. 关于websocket

    一句话总结: websocket可以说是基于HTTP但有有所进化的一个介于应用层和传输层的接口抽象,不是协议. 1 需要基于HTTP进行3次握手,4次挥手(在握手期间建立websocket连接,不再通 ...

  5. HTTP 错误 500.21 - Internal Server Error 解决方案(转)

    不久前重新安装了Windows7,在安装了VS2010 开发平台之后,将网站发布到IIS,访问发生如下错误: HTTP 错误 500.21 - Internal Server Error处理程序“Ni ...

  6. MySQL数据库(3)- 完整性约束、外键的变种、单表查询

    一.完整性约束 在创建表时候,约束条件和数据类型的宽度都是可选参数. 作用:用于保证数据的完整性和一致性. 1.not null(不可空)与default 示例一:插入一个空值,如下: mysql&g ...

  7. change the color of a disabled TEdit?

    change the color of a disabled TEdit? Author: P. Below Category: VCL {Question:How can I change the  ...

  8. is和==

    ==判断两个对象值是否相等 is表示两个变量是否指向一块对象

  9. kubeadm方式安装kubernetes

    系统: Ubuntu 18.04.2 LTS 内存: 8G 机器: 属性 IP Hostname ssh  Master  192.168.91.48 blackray-pc     node1  1 ...

  10. mybatis参数处理 $#