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. Django学习案例一(blog):六. 开发博客内容页面

    目标:某条博客具体内容的展示,可返回博客主页面,可进行评论. 1. 编辑路由 一篇博客,要将其找出来,就需要有一个唯一的标识.Django 的模型中默认有一个唯一的且未自增长的主键,即 id 字段.我 ...

  2. Android贝塞尔曲线应用-跳动的水滴

    主要通过6个控制点实现. val startPoint = PointF() val endPoint = PointF() val control1 = PointF() val control2 ...

  3. DeltaFish 校园物资共享平台 第三次小组会议

    一.想法 娄雨禛: 网页底层开发转移到后端,快速建站,效率高. 可以依照模板进行仿制. 可以考虑只进行页面设计. 但是出现问题不会调试. 所以自己写源码,做出一个大致的样子. 二.上周进度汇报 齐天杨 ...

  4. linux 新添加的硬盘格式化并挂载到目录下

    需求: 新增加一块硬盘sdb,将sdb分区,只分一个区,格式化,挂载到目录/ssd下. 1.  查看现在已有的分区状态 # df –l 图中显示,没有看到sdb硬盘 2.  查看服务器安装的硬盘状态( ...

  5. rev

    功能说明:反向输出文件内容.   字符串反转   文本反转

  6. MySQL常用增删改查等操作语句

    修改数据库的字符集    mysql>use mydb    mysql>alter database mydb character set utf8;创建数据库指定数据库的字符集    ...

  7. Linux内核tracepoints

    Linux内核tracepoints 简单介绍 内核中的每个tracepoint提供一个钩子来调用probe函数. 一个tracepoint可以打开或关闭.打开时,probe函数关联到tracepoi ...

  8. jQuery升级踩坑之路

    1.使用了被废弃的jQuery.browser属性 jQuery 从 1.9 版开始,移除了 $.browser 和 $.browser.version , 取而代之的是 $.support . 在更 ...

  9. (ccf模拟)201709-2公共钥匙盒

    #include <iostream> #include<string> #include <algorithm> #include<sstream> ...

  10. lua返回页面时中文乱码

    1.在nginx.conf文件中的server标签里添加charset utf-8; 2.查看lua文件编码是否为utf-8