Spring ProxyFactory
ProxyFactory 是 Spring AOP的实现方式之一。下面介绍下ProxyFactory的用法。
1、接口定义
public interface UserReadService {
public UserInfo getUserInfoById(Long id);
}
2、接口实现
public class UserReadServiceImpl implements UserReadService {
@Override
public UserInfo getUserInfoById(Long id) {
System.out.println("获取用户信息");
return null;
}
}
3、拦截器定义
public class UserInterceptor implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
System.out.println("start");
Object obj = invocation.proceed();
System.out.println("end");
return obj;
}
}
4、测试
public static void main(String[] args) {
ProxyFactory factory = new ProxyFactory(new UserReadServiceImpl());
factory.addAdvice(new UserInterceptor());
UserReadService userReadService = (UserReadService) factory.getProxy();
userReadService.getUserInfoById(null);
}
结果:
start
获取用户信息
end
Spring ProxyFactory的更多相关文章
- Spring的增强模式
一.前置增强 1.IdoSomeService 2.IdoSomeServiceImpl类实现IdoSomeService接口 3.MyBeforeAdvice 实现前置增强方法 4.applicat ...
- Spring——代理工厂实现增强
借助Spring IOC的机制,为ProxyFactory代理工厂的属性实现依赖注入,这样做的优点是可配置型高,易用性好. 1.创建抽象主题 public interface ProService { ...
- 曹工说Spring Boot源码(20)-- 码网灰灰,疏而不漏,如何记录Spring RedisTemplate每次操作日志
写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...
- 多种方式实现AOP
一.使用代理工厂完成声明式增强 1.创建业务接口 public interface IdoSomeService { public void doSomething(); } 2.创建接口实现类 pu ...
- SpringAOP进阶
利用代理工厂实现增强 com.Spring.proxyfactory中的IdoSomeService package cn.spring.proxyfactory; public interface ...
- 代理实现aop以及代理工厂实现增强
一.静态代理实现 1.接口(抽象主题) 2.接口的实现类(真实主题) 3.代理类(代理主题) 4.测试类: ApplicationContext context=new ClassPathXmlApp ...
- Spring Aop(十一)——编程式的创建Aop代理之ProxyFactory
转发地址:https://www.iteye.com/blog/elim-2397388 编程式的创建Aop代理之ProxyFactory Spring Aop是基于代理的,ProxyFactory是 ...
- 曹工说Spring Boot源码(19)-- Spring 带给我们的工具利器,创建代理不用愁(ProxyFactory)
写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...
- 曹工说Spring Boot源码(21)-- 为了让大家理解Spring Aop利器ProxyFactory,我已经拼了
写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...
随机推荐
- P117、面试题18:树的子结构
题目:输入两棵二叉树A和B,判断B是不是A的子结构.二叉树结点的定义如下:struct BinaryTreeNode{ int m_nValue; BinaryTreeNod ...
- hadoop2.2.0安装
64位编译和安装 http://blog.csdn.net/licongcong_0224/article/details/12972889 http://blog.csdn.net/w1377026 ...
- NFC(10)NDEF uri格式规范及读写示例(解析与封装ndef uri)
只有遵守NDEF uri 格式规范的数据才能写到nfc标签上. NDEF uri 格式规范 uri 只有两部分: 第1个字节是uri协议映射值,如:0x01 表示uri以 http://www.开头. ...
- How to install GSL on linux(ubuntu,centos,redhat)
Test: ftp://ftp.gnu.org/gnu/gsl/gsl-1.15.tar.gz success. ftp://ftp.gnu.org/gnu/gsl/gsl-1.13.0.tar.g ...
- mysqld -install命令时出现install/remove of the service denied错误的原因和解决办法
原因:没有使用管理员权限 解决方法:使用管理员权限打开cmd,然后运行mysqld -install,服务安装成功
- mysql中php生成唯一ID
<?php //uniqid官方手册 function create_guid($namespace = '') { static $guid = ''; $uid = uniqid(" ...
- Java [leetcode 35]Search Insert Position
题目描述: Given a sorted array and a target value, return the index if the target is found. If not, retu ...
- hdu 2844 Coins
Coins Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total Submission(s): Accepted S ...
- NFA和DFA区别
一个数据块的访问时间等于寻道时间.旋转延迟时间和数据传输时间三者之和: NFA和DFA区别: 一个状态如A,遇0可以转换到下一个状态B或C,因为选择多所以不确定,因此为不确定的有限自动机: 一个状态还 ...
- Gradle使用手册(三):构建任务
原文地址:http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Using-sourceCompatibility-1. ...