在 xml中加

xmlns:aop="http://www.springframework.org/schema/aop"

http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">

<aop:aspectj-autoproxy />

然后再要添加的方法前添加

@Aspect
@Component

在然后写织入点语法

@Pointcut("execution(public * com.bjsxt.service..*.add(..))")

public void myMethod(){};

@Before("myMethod()")

写添加方法

@Around("myMethod()")

写添加方法

例如:

package com.bjsxt.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogInterceptor {
@Pointcut("execution(public * com.bjsxt.service..*.add(..))")
public void myMethod(){};

@Before("myMethod()")
public void before() {
System.out.println("method before");
}

@Around("myMethod()")
public void aroundMethod(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("method around start");
pjp.proceed();
System.out.println("method around end");
}

}

还有一种是把aop写在xml文件中

<bean id="logInterceptor" class="com.bjsxt.aop.LogInterceptor"></bean>
<aop:config>

<aop:aspect id="logAspect" ref="logInterceptor">
<aop:before method="before" pointcut="execution(public * com.bjsxt.service..*.add(..))" />
</aop:aspect>

</aop:config>

package com.bjsxt.aop;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

//@Aspect
//@Component
public class LogInterceptor {
//@Pointcut("execution(public * com.bjsxt.service..*.add(..))")
public void myMethod(){};

//@Before("myMethod()")
public void before() {
System.out.println("method before");
}

//@Around("myMethod()")
public void aroundMethod(ProceedingJoinPoint pjp) throws Throwable {
System.out.println("method around start");
pjp.proceed();
System.out.println("method around end");
}

}

Spring AOP 整理的更多相关文章

  1. Spring AOP整理

    示例展示 AOP(Aspect Oriented Programming),是面向切面编程的技术.AOP基于IoC基础,是对OOP的有益补充.AOP之所以能得到广泛认可,主要是因为它将应用系统拆分分了 ...

  2. Spring AOP 整理笔记

    一.AOP概念 AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术. 利用AOP可以对业务逻辑的各 ...

  3. AOP面试知识整理,^_^-包括spring Aop

    讲到java企业级开发框架,就不可避免的讲到 IOC,AOP,MCV 今天面试时被问到AOP,讲的很乱,这里整理笔记,包括AOP,spring-AOP的部分知识,错误的地方请小伙伴指出来. 谈谈你对A ...

  4. Spring AOP使用整理:各种通知类型的介绍

    2.PersonImpl类的源码 public class PersonImpl implements Person { private String name; private int age; p ...

  5. Spring AOP 知识整理

    通过一个多月的 Spring AOP 的学习,掌握了 Spring AOP 的基本概念.AOP 是面向切面的编程(Aspect-Oriented Programming),是基于 OOP(面向对象的编 ...

  6. 用心整理 | Spring AOP 干货文章,图文并茂,附带 AOP 示例 ~

    Spring AOP 是 Java 面试的必考点,我们需要了解 AOP 的基本概念及原理.那么 Spring AOP 到底是啥,为什么面试官这么喜欢问它呢?本文先介绍 AOP 的基本概念,然后根据 A ...

  7. 利用反射手写代码实现spring AOP

    前言:上一篇博客自己动手编写spring IOC源码受到了大家的热情关注,在这里博客十分感谢.特别是给博主留言建议的@玛丽的竹子等等.本篇博客我们继续,还是在原有的基础上进行改造.下面请先欣赏一下博主 ...

  8. [Spring框架]Spring AOP基础入门总结一.

    前言:前面已经有两篇文章讲了Spring IOC/DI 以及 使用xml和注解两种方法开发的案例, 下面就来梳理一下Spring的另一核心AOP. 一, 什么是AOP 在软件业,AOP为Aspect ...

  9. 【Spring】Spring AOP实现原理

    Spring AOP实现原理 在之前的一文中介绍过Spring AOP的功能使用,但是没有深究AOP的实现原理,今天正好看到几篇好文,于是就自己整理了一下AOP实现的几种方式,同时把代理模式相关知识也 ...

随机推荐

  1. Linux文件属性,类型,ls -lhi解释行列

    Linux文件属性(描述信息) -i inode节点号 -h 人类可读 ls -lhi 1703938 drwxr-xr-x 2 rsync rsync 4.0K Jun 7 07:24 gamese ...

  2. http的含义

    HTTP是超文本传输协议,是客户端浏览器或其他程序与Web服务器之间的应用层通信协议.在Internet上的Web服务器上存放的都是 超文本信息,客户机需要通过HTTP协议传输所要访问的超文本信息.H ...

  3. Windows远程桌面连接CentOS 7

    1. 安装tigervnc-server yum install tigervnc-server 2. 设置vncserver服务器 将默认提供的文件复制到/etc/systemd/system,命令 ...

  4. Python web框架 Tornado(一)基础学习

    概述 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 webapp,不过为了 ...

  5. nginx的下载和安装

    安装 下载必要组件 nginx下载地址 http://nginx.org/en/download.html  pcre库下载地址,nginx需要[解析正则] http://sourceforge.ne ...

  6. RHCE7-学习里程 root 密码重置换

    一.root 密码重置换 当忘记root 密码后,可以按照以下方法重置 root 密码 1.重启动电脑,出现如下界面,按  上  下 键盘, 选择   (core)--再按e 2.在下图linux16 ...

  7. C++Primer笔记-----day02

    ====================================================================day02=========================== ...

  8. awk 数据处理小技巧

    进行数据分析或统计时,如果数据量较小,我们可以用awk快速处理,以下是一些小技巧   一.时间戳转换 日期转时间戳: date -d "20150315"  "+%s&q ...

  9. WCF配置多个终节点

    配置多个终节点的意义(自己理解):一个服务可以有多个终节点,网上也经常有人说终节点才是服务的真正的接口,的确如此,当我们为一个服务配置多个终节点时,就表明这个服务可以被以不同的方式访问(不同的绑定等等 ...

  10. 运动函数封装(js)

    // 运动函数 function starMove(obj,json,fnEnd){ clearInterval(obj.timer); obj.timer  = setInterval(functi ...