自从上班之后,就很少再看AOP相关的内容,几年时间里虽然也有一两次完整看过,一直没有机会用到,都忘记了。今天重温一下

TestNG测试类

package com.test.spring.aop.mineunderstatnd1;

import java.util.HashMap;
import java.util.Map; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test; @ContextConfiguration(classes={AppConfig.class})
public class RechargeTest extends AbstractTestNGSpringContextTests{ @Autowired
private AccountRecharge accountRecharge; @Autowired
private Interceptor interceptor; @Test
public void test() {
Map request = new HashMap();
accountRecharge.execute(request);
}
}

业务类

package com.test.spring.aop.mineunderstatnd1;

import java.util.HashMap;
import java.util.Map; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test; @ContextConfiguration(classes={AppConfig.class})
public class RechargeTest extends AbstractTestNGSpringContextTests{ @Autowired
private AccountRecharge accountRecharge; @Autowired
private Interceptor interceptor; @Test
public void test() {
Map request = new HashMap();
accountRecharge.execute(request);
}
}

切面类

@Aspect
public class Interceptor {
@Pointcut("execution(* com.test.spring.aop.mineunderstatnd1.AccountRecharge.execute(java.util.Map)) && args(request)")
public void execute(HashMap request){}
@Before("execute(request)")
public void before(HashMap request) {
System.out.println("前置拦截器");
}
}

配置类

package com.test.spring.aop.mineunderstatnd1;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy; @Configuration
@EnableAspectJAutoProxy
@ComponentScan
public class AppConfig {
@Bean
public AccountRecharge AccountRecharge() {
return new AccountRecharge();
}
@Bean
public Interceptor interceptor() {
return new Interceptor();
}
}

运行结果:

前置拦截器
do recharge
PASSED: test

SpringAOP学习第一天 @Pointcut注解的更多相关文章

  1. spring-aop学习

     SpringAOP学习 author:luojie 1.  AOP中的基本概念 AOP的通用术语,并非spring java所特有.很遗憾AOP的术语不是特别的直观.但如果让Spring java来 ...

  2. 19Spring_AOP编程(AspectJ)_使用@Pointcut注解来定义切点

    我们之前的方式是采用 @AfterReturning(value="execution(* com.guigu.shen.anotion.UserDaoImpl.*(..))",r ...

  3. 从.Net到Java学习第一篇——开篇

    以前我常说,公司用什么技术我就学什么.可是对于java,我曾经一度以为“学java是不可能的,这辈子不可能学java的.”结果,一遇到公司转java,我就不得不跑路了,于是乎,回头一看N家公司交过社保 ...

  4. springmvc学习笔记(12)-springmvc注解开发之包装类型參数绑定

    springmvc学习笔记(12)-springmvc注解开发之包装类型參数绑定 标签: springmvc springmvc学习笔记12-springmvc注解开发之包装类型參数绑定 需求 实现方 ...

  5. Magento学习第一课——目录结构介绍

    Magento学习第一课--目录结构介绍 一.Magento为何强大 Magento是在Zend框架基础上建立起来的,这点保证了代码的安全性及稳定性.选择Zend的原因有很多,但是最基本的是因为zen ...

  6. YII2学习第一天

    YII2学习第一天,之前稍微看了看TP,感觉和自己的理念不是很符合,然后转学YII2了. 使用的文档是https://github.com/yiisoft/yii2/tree/master/docs/ ...

  7. Java学习第一天

    Java学习第一天 对于网络管理员或者黑客必须知道的八个cmd命令 详情请参考:http://www.2cto.com/os/201608/533964.html          nbtstat  ...

  8. 一、Android学习第一天——环境搭建(转)

    (转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 一. Android学习第一天——环境搭建 Android 开发环境的搭建 ...

  9. web学习第一章

    web学习第一章   我是大概9月10日开始走上IT之路的,一开始学习了小段时间的自动化办公软件, 昨天我开始学习客户端网页编程,我了解什么是WEB,一些比较老古董的计算模式和发展历史,印象最让我深刻 ...

随机推荐

  1. js/jquery控制页面动态加载数据 滑动滚动条自动加载事件--转他人的

    js/jquery控制页面动态加载数据 滑动滚动条自动加载事件--转他人的 相信很多人都见过瀑布流图片布局,那些图片是动态加载出来的,效果很好,对服务器的压力相对来说也小了很多 有手机的相信都见过这样 ...

  2. gcc和gdb使用笔记

    gcc: http://wiki.ubuntu.org.cn/Gcchowto gdb: http://wiki.ubuntu.org.cn/%E7%94%A8GDB%E8%B0%83%E8%AF%9 ...

  3. idea常用快捷键及自定义快捷键汇总

    以下都是挨个进行验证过的 生成get和set方法为:alt+insert 自动补全返回值,自动补全变量名称和属性名称:ctrl+alt+v 输入System.out.println()的快捷方法是:输 ...

  4. SmartUpload文件上传组件的使用教程

    在项目中使用SmartUpload组件可以进行文件的上传和下载操作 使用步骤 1.导入jar包,进行build path操作 2.编写文件上传页面,代码如下 <form action=" ...

  5. Java——Struts2 之国际化 struts.custom.i18n.resources=globalMessages

    1.在src下 建立 struts.properties 文件,内容为:struts.custom.i18n.resources=globalMessages struts.custom.i18n.r ...

  6. entity framework 时间操作

    ).FirstOrDefault(); if (useractiveentity == null) { UserActive userActive = new UserActive(); userAc ...

  7. Elastic Job入门(1) - 简介

    介绍 构建一般的业务系统来说,使用Quartz或者Spring Task即可基本满足我们的单体服用应用需要.然而随着线上业务量的不断发展,这两种定时任务已经日渐无法满足我们的需求.一般,使用这两种定时 ...

  8. [转]mmap和madvise的使用

    1.    madvise的简介            madvise可以设置内存的分配方式或者说是分配的细节方式.具体参见linux man madvise. #include <sys/ty ...

  9. caffe中使用python定义新的层

    转载链接:http://withwsf.github.io/2016/04/14/Caffe-with-Python-Layer/ Caffe通过Boost中的Boost.Python模块来支持使用P ...

  10. openwrt 分区

    下面以ar9344 16M flash为例子: uboot启动时传递给内核的参数为: bootargs=console=ttyS0,115200 root=31:02 rootfstype=jffs2 ...