SpringAOP学习第一天 @Pointcut注解
自从上班之后,就很少再看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注解的更多相关文章
- spring-aop学习
SpringAOP学习 author:luojie 1. AOP中的基本概念 AOP的通用术语,并非spring java所特有.很遗憾AOP的术语不是特别的直观.但如果让Spring java来 ...
- 19Spring_AOP编程(AspectJ)_使用@Pointcut注解来定义切点
我们之前的方式是采用 @AfterReturning(value="execution(* com.guigu.shen.anotion.UserDaoImpl.*(..))",r ...
- 从.Net到Java学习第一篇——开篇
以前我常说,公司用什么技术我就学什么.可是对于java,我曾经一度以为“学java是不可能的,这辈子不可能学java的.”结果,一遇到公司转java,我就不得不跑路了,于是乎,回头一看N家公司交过社保 ...
- springmvc学习笔记(12)-springmvc注解开发之包装类型參数绑定
springmvc学习笔记(12)-springmvc注解开发之包装类型參数绑定 标签: springmvc springmvc学习笔记12-springmvc注解开发之包装类型參数绑定 需求 实现方 ...
- Magento学习第一课——目录结构介绍
Magento学习第一课--目录结构介绍 一.Magento为何强大 Magento是在Zend框架基础上建立起来的,这点保证了代码的安全性及稳定性.选择Zend的原因有很多,但是最基本的是因为zen ...
- YII2学习第一天
YII2学习第一天,之前稍微看了看TP,感觉和自己的理念不是很符合,然后转学YII2了. 使用的文档是https://github.com/yiisoft/yii2/tree/master/docs/ ...
- Java学习第一天
Java学习第一天 对于网络管理员或者黑客必须知道的八个cmd命令 详情请参考:http://www.2cto.com/os/201608/533964.html nbtstat ...
- 一、Android学习第一天——环境搭建(转)
(转自:http://wenku.baidu.com/view/af39b3164431b90d6c85c72f.html) 一. Android学习第一天——环境搭建 Android 开发环境的搭建 ...
- web学习第一章
web学习第一章 我是大概9月10日开始走上IT之路的,一开始学习了小段时间的自动化办公软件, 昨天我开始学习客户端网页编程,我了解什么是WEB,一些比较老古董的计算模式和发展历史,印象最让我深刻 ...
随机推荐
- Study 4 —— 数据类型(1)
基本类型数字字符串布尔 数字 整数 int 在32位机器上,整数的位数为32位,取值范围为-2**31~2**30 在64位机器上,整数的位数为64位,取值范围为-2**63~2**62 ...
- 单源最短路径问题(dijkstra算法 及其 优化算法(优先队列实现))
#define _CRT_SECURE_NO_WARNINGS /* 7 10 0 1 5 0 2 2 1 2 4 1 3 2 2 3 6 2 4 10 3 5 1 4 5 3 4 6 5 5 6 9 ...
- linux的基本操作与常见命令
linux的基本操作与常见命令: jdk的安装: 步骤:(特别注意:虚拟机安装的一般是32位的操作系统,jdk也必须使用32位的) 查看虚拟机版本:sudo uname --m i686 //表示是3 ...
- springboot(八)自定义Filter、自定义Property
自定义Filter 我们常常在项目中会使用filters用于录调用日志.排除有XSS威胁的字符.执行权限验证等等. Spring Boot自动添加了OrderedCharacterEncodingFi ...
- Mysql高级查询 内连接和外连接详解
一.内连接(INNER JOIN) 1.等值连接 概述:指使用等号"="比较两个表的连接列的值,相当于两表执行笛卡尔后,取两表连结列值相等的记录. 语法: SELECT 列 FRO ...
- FCN 32分析:
FCN 32s
- Nginx 内核优化
内核参数的优化示例: /etc/sysctl.conf net.ipv4.tcp_max_tw_buckets = // timewait的数量,默认是180000. net.ipv4.ip_loca ...
- NOIP2018TG题解
应该不会被禁赛吧qwq Day1 T1 铺设道路 €€£:我 抄 我 自 己 我考场上写的是一个类似于差分的做法,就是开个数组表示某个位置是否贡献答案,从小到大枚举高度,那么一个位置能贡献答案当且仅当 ...
- 20165227《网络对抗技术》Exp0 Kali安装 Week1
2018-2019-2 <网络对抗技术>Exp0 Kali安装 Week1 kali下载:镜像文件通过同学获得 kali具体安装步骤: 打开VMware,点击新建虚拟机,进行创建 创建完成 ...
- 文加图, 理解Http请求与响应
1. http请求和响应步骤 在讲解OkHttp之前, 我们首先来个高清大图, 看下http请求的整个步骤, 有个整体概念. 2. http每一步详细内容 在一次完整的HTTP通信过程中, Web浏 ...