1.引入相关的jar包

2.建两个类

public class Book {
public void add(){
System.out.println("add-----------");
}
}
import org.aspectj.lang.ProceedingJoinPoint;
public class MyBook {
public void before(){
System.out.println("前置輸出----------");
}
public void after(){
System.out.println("后置输出----------");
}
public void around(ProceedingJoinPoint proceedingJoinPoint) throws Throwable{
System.out.println("方法之前");
proceedingJoinPoint.proceed();
System.out.println("方法之后");
}
}

3.在配置文件中完成相关的配置

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd">
<bean id="book" class="com.example.aop.Book"></bean>
<bean id="myBook" class="com.example.aop.MyBook"></bean>
<!-- 配置aop方式 -->
<aop:config>
<!-- 配置切入點 -->
<aop:pointcut expression="execution(* com.example.aop.Book.*(..))" id="pointcut1"/>
<!-- 配置切面
把增强用到方法中去
-->
<aop:aspect ref="myBook">
<!-- 配置增强类型
method:增强类里面使用哪个方法作为前置
-->
<aop:before method="before" pointcut-ref="pointcut1"/>
<aop:after method="after" pointcut-ref="pointcut1"/>
<aop:around method="around" pointcut-ref="pointcut1"/>
</aop:aspect>
</aop:config> </beans>

4.建一个测试类 ,测试输出

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.example.aop.Book;
import comexample.ano1.BookService;
public class TestAno {
@Test
public void testService() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"bean3.xml");
Book book=(Book) context.getBean("book");
book.add();
}
}

基于aspectj的aop的操作的更多相关文章

  1. 基于aspectj的aop注解操作

  2. 利用基于@AspectJ的AOP实现权限控制

    一. AOP与@AspectJ AOP 是 Aspect Oriented Programming 的缩写,意思是面向方面的编程.我们在系统开发中可以提取出很多共性的东西作为一个 Aspect,可以理 ...

  3. Spring 基于 AspectJ 的 AOP 开发

    Spring 基于 AspectJ 的 AOP 开发 在 Spring 的 aop 代理方式中, AspectJ 才是主流. 1. AspectJ 简介 AspectJ 是一个基于 java 语言的 ...

  4. [Spring框架]Spring AOP基础入门总结二:Spring基于AspectJ的AOP的开发.

    前言: 在上一篇中: [Spring框架]Spring AOP基础入门总结一. 中 我们已经知道了一个Spring AOP程序是如何开发的, 在这里呢我们将基于AspectJ来进行AOP 的总结和学习 ...

  5. 基于aspectj实现AOP操作的两种方式——xml配置

    1. 要导入的 jar 包: 常用的aspectj表达式: 权限修饰符可以省略,以下表示:返回值类型为任意,com.chy.service包以及其子包下的.任意类的.参数任意的.任意方法 execut ...

  6. 基于aspectj实现AOP操作的两种方式——注解方式

  7. Spring基于AspectJ的AOP的开发——注解

    源码:https://gitee.com/kszsa/dchart 一, AspectJ的概述: AspectJ是一个面向切面的框架,它扩展了Java语言.AspectJ定义了AOP语法所以它有一个专 ...

  8. Spring框架学习09——基于AspectJ的AOP开发

    1.基于注解开发AspectJ (1)AspectJ注解 基于注解开发AspectJ要比基于XML配置开发AspectJ便捷许多,所以在实际开发中推荐使用注解方式.关于注解的相关内容如下: @Aspe ...

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

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

随机推荐

  1. java热部署

    最近使用java做项目,研究了一下热部署,能够提高工作效率. 需要准备的工具: 1.安装文件http://update.zeroturnaround.com/update-site/ 2.破解 下载破 ...

  2. 谈谈对Java中Unicode、编码的理解

    我们经常会遇到编码问题.Java号称国际化的语言,是因为它的class文件采用UTF-8,而JVM运行时使用UTF-16(至于为什么JVM中要采用UTF-16,我没看过 相关的资料,但我猜可能是因为J ...

  3. 使用TortoiseSVN碰到的几个问题(2)-冲突解决, 图标重载

    8)解决冲突 冲突分为两种:文件冲突---当两名(或更多)开发人员修改了同一个文件中相邻或相同的行时就会发生文件冲突.下面的属性冲突应该也属于文件冲突. 树冲突---当一名开发人员移动.重命名.删除一 ...

  4. 错误:android.view.InflateException: Binary XML file line #167: Binary XML file line #167: Error inflating class <unknown>

    1:错误日志 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.8.activity.RecordActiv ...

  5. Android媒体解码MediaCodec MediaExtractor学习

    Android提供了MediaPlayer播放器播放媒体文件,其实MediaPlyer只是对Android Media包下的MediaCodec和MediaExtractor进行了包装,方便使用.但是 ...

  6. 省市区县的sql语句——省

    /*SQLyog v10.2 MySQL - 5.5.48 : Database - 省市县****************************************************** ...

  7. HDU_1711_初识KMP算法

    Number Sequence Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. jq遍历table 下的 td 添加类

    <script> $('#btntb').click(function () { $('#tab tr').each(function (i) { // 遍历 tr $(this).chi ...

  9. Having子句用法

    Having基础用法 集合结果指定条件 注:HAVING子句中能够使用三种要素:常数,聚合函数,GROUP BY子句中指定的列名(聚合建) HAVING子句: 用having就一定要和group by ...

  10. 在阿里云的ubuntu服务器上安装xampp时出现unable to realloc unable to realloc 8380000 bytes错误

    在阿里云的ubuntu服务器上安装xampp时出现unable to realloc unable to realloc 8380000 bytes错误 解决:增加Swap空间(阿里云缺省没有分配任何 ...