自从上班之后,就很少再看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. 使用JavaScript修改浏览器URL地址栏的实现代码【转】

    引用自http://www.jb51.net/article/42240.htm 现在的浏览器里,有一个十分有趣的功能,你可以在不刷新页面的情况下修改浏览器URL;在浏览过程中.你可以将浏览历史储存起 ...

  2. Nginx 中 FastCGI 配置示例

    nginx 中 FastCGI 参数:主要是在 http 层 :保证PHP环境的高校运行 主要对PHP用来解析 fastcgi_cache_path /tmp/fastcgi_cache levels ...

  3. Anaconda的安装和更新

    下载地址官网:https://www.anaconda.com/distribution/ 一.安装 二.下载安装完成后我们来检验一下是否安装成功 点击“开始” —— “Anaconda3(64-bi ...

  4. <hr />改变颜色

    其实,<hr />是有默认的border的,改变border颜色即可改变hr颜色. 例如: <hr style="position: relative;top: 2.3re ...

  5. JavaScript之Array/数组小结

    MDN-Array的属性/方法:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Arr ...

  6. USB摄像头无法正常读取问题

    opencv读取摄像头或者视频一种是早期版本的IplImage结构体,图片就存在结构体指针IplImage*中,另一种是Mat类,两者在操作上略有差异,且opencv2都兼容这两个版本,前面的博客也说 ...

  7. luogu P4161 [SCOI2009]游戏

    传送门 我们发现整个大置换中,会由若干形如\((a_1\rightarrow a_2,a_2\rightarrow a_3,...a_{n-1}\rightarrow a_n,a_n\rightarr ...

  8. sql server 查询某个时间段共有多少周及每周的日期段

    sql 语句 as wknum,dateadd(wk,number,'2017-01-01') as firstday, (,, then '2017-12-31' ,,'2017-01-01')) ...

  9. oracle_数据库对象

  10. Spring使用RMI进行远程方法调用

    (1).我新建了三个项目,SpringRmiApi(存放提供者和消费者共有的xx,例如实体类以及服务接口等等).SpringRmiService(服务提供者).SpringRmiProvider(服务 ...