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. 【Oracle】体系结构

    1. 理解实例和数据库 ☞ 实例是一组后台进程和共享内存 ☞ 数据库是磁盘上存储的数据集合 ☞ 实例“一生”只能装载并打开一个数据库 ☞ 数据库可以由一个或多个实例(RAC)装载和打开 [oracle ...

  2. Inception搭建

    Inception安装Inception是集审核.执行.回滚于一体的一个自动化运维系统,它是根据MySQL代码修改过来的,用它可以很明确的,详细的,准确的审核MySQL的SQL语句,它的工作模式和My ...

  3. JAVA语言编程格式高级规范

    作为一位开发人员,都要有严格的代码规范.为此我总结了一些代码规范案例. 目   录 1. 前言 2. 试用范围 3. JAVA命名规范-- 3.1 公共约定 3.2 Java文件.包 3.3 类.接口 ...

  4. 3、scala函数入门

    1.定义函数 2.在代码块中定义函数体 3.递归函数与返回类型 4.默认参数 5.带名参数 6.变长参数 7.使用序列调用变长参数  8.过程 9.lazy值              10.异常 1 ...

  5. python3:语法变动 及新特性

    python3.0 对python2.x 升级后重大语法变动,幸好留下2.7.6及后续2版本,保持一些语法兼容. 原始地址:http://hi.baidu.com/jxq61/item/3a24883 ...

  6. 【sqli-labs】 less6 GET - Double Injection - Double Quotes - String (双注入GET双引号字符型注入)

    同less5 单引号改成双引号就行 http://localhost/sqli/Less-6/?id=a" union select 1,count(*),concat((select ta ...

  7. (转)基于Metronic的Bootstrap开发框架经验总结(6)--对话框及提示框的处理和优化

    http://www.cnblogs.com/wuhuacong/p/4775282.html 在各种Web开发过程中,对话框和提示框的处理是很常见的一种界面处理技术,用得好,可以给用户很好的页面体验 ...

  8. javaee IO流打印一行的方式

    package Dayin; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.F ...

  9. Swoole server函数列表(转载)

    swoole_server::__construct swoole_server::set swoole_server::on swoole_server::addlistener swoole_se ...

  10. JAVA 生成扫描条形码

    声明:转载为个人学习收藏,如有侵权,请及时联系本人删除,转载地址:https://www.cnblogs.com/MariaWang/p/10837641.html 条形码是一种可视化.机器可读的数据 ...