基于aspectj的aop的操作
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的操作的更多相关文章
- 基于aspectj的aop注解操作
- 利用基于@AspectJ的AOP实现权限控制
一. AOP与@AspectJ AOP 是 Aspect Oriented Programming 的缩写,意思是面向方面的编程.我们在系统开发中可以提取出很多共性的东西作为一个 Aspect,可以理 ...
- Spring 基于 AspectJ 的 AOP 开发
Spring 基于 AspectJ 的 AOP 开发 在 Spring 的 aop 代理方式中, AspectJ 才是主流. 1. AspectJ 简介 AspectJ 是一个基于 java 语言的 ...
- [Spring框架]Spring AOP基础入门总结二:Spring基于AspectJ的AOP的开发.
前言: 在上一篇中: [Spring框架]Spring AOP基础入门总结一. 中 我们已经知道了一个Spring AOP程序是如何开发的, 在这里呢我们将基于AspectJ来进行AOP 的总结和学习 ...
- 基于aspectj实现AOP操作的两种方式——xml配置
1. 要导入的 jar 包: 常用的aspectj表达式: 权限修饰符可以省略,以下表示:返回值类型为任意,com.chy.service包以及其子包下的.任意类的.参数任意的.任意方法 execut ...
- 基于aspectj实现AOP操作的两种方式——注解方式
- Spring基于AspectJ的AOP的开发——注解
源码:https://gitee.com/kszsa/dchart 一, AspectJ的概述: AspectJ是一个面向切面的框架,它扩展了Java语言.AspectJ定义了AOP语法所以它有一个专 ...
- Spring框架学习09——基于AspectJ的AOP开发
1.基于注解开发AspectJ (1)AspectJ注解 基于注解开发AspectJ要比基于XML配置开发AspectJ便捷许多,所以在实际开发中推荐使用注解方式.关于注解的相关内容如下: @Aspe ...
- 第三章 AOP 基于@AspectJ的AOP
在前面,我们分别使用Pointcut.Advice.Advisor接口来描述切点.增强.切面.而现在我们使用@AdpectJ注解来描述. 在下面的例子中,我们是使用Spring自动扫描和管理Bean. ...
随机推荐
- vue-router简单用法
路由,其实就是指向的意思,当我点击页面上的home按钮时,页面中就要显示home的内容,如果点击页面上的about 按钮,页面中就要显示about 的内容.Home按钮 => home 内容, ...
- Error:CreateProcess error=216的错误,JDK版本不匹配问题。
今天刚下载安装完android studio,结果随便新建一个工程的时候就出现了如下提示: Error:CreateProcess error=216, 该版本的 %1 与您运行的 Windows 版 ...
- VHDL之FSM
1 Intro The figure shows the block diagram of a single-phase state machine. The lower section contai ...
- SQL Server之十大存储过程
下面介绍十大不同类型存储过程. 用户自定义存储过程 . 创建语法 create proc | procedure pro_name [{@参数数据类型} [=默认值] [output], {@参数数据 ...
- MyEclipse 连接Oracle数据库(初学者必看)
前言:刚接触Oracle数据库,便有一个需求,编写控制台程序,实现主人登录.数据库为Oracle.下面详细介绍一下MyEclipse 连接Oracle数据库. package DbHelp; im ...
- centos开机运行级别更改
1.使用命令切换运行级别/目标 # systemctl isolate multi-user.target //切换到运行级别3,该命令对下次启动无影响,等价于telinit 3 # systemct ...
- 使用GitGUI创建上传本地工程
参考链接: 使用Git-GUI创建工程 http://jingyan.baidu.com/article/27fa732683ebf546f8271f2e.html 一.刚创建的github版本库,在 ...
- Visual Studio Code 插件推荐
Path Intellisense - 路径补全 HTML Snippets - HTML 标记增强 Markdown+Math - Markdown 增强(数学表达式) vscode-icons - ...
- js 习题
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- 08 Django组件-Forms组件
Django的Forms组件主要有以下几大功能: 页面初始化,生成HTML标签 校验用户数据(显示错误信息) HTML Form提交保留上次提交数据 一.小试牛刀 1.定义Form类 from dja ...