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的更多相关文章

  1. Spring的增强模式

    一.前置增强 1.IdoSomeService 2.IdoSomeServiceImpl类实现IdoSomeService接口 3.MyBeforeAdvice 实现前置增强方法 4.applicat ...

  2. Spring——代理工厂实现增强

    借助Spring IOC的机制,为ProxyFactory代理工厂的属性实现依赖注入,这样做的优点是可配置型高,易用性好. 1.创建抽象主题 public interface ProService { ...

  3. 曹工说Spring Boot源码(20)-- 码网灰灰,疏而不漏,如何记录Spring RedisTemplate每次操作日志

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...

  4. 多种方式实现AOP

    一.使用代理工厂完成声明式增强 1.创建业务接口 public interface IdoSomeService { public void doSomething(); } 2.创建接口实现类 pu ...

  5. SpringAOP进阶

    利用代理工厂实现增强 com.Spring.proxyfactory中的IdoSomeService package cn.spring.proxyfactory; public interface ...

  6. 代理实现aop以及代理工厂实现增强

    一.静态代理实现 1.接口(抽象主题) 2.接口的实现类(真实主题) 3.代理类(代理主题) 4.测试类: ApplicationContext context=new ClassPathXmlApp ...

  7. Spring Aop(十一)——编程式的创建Aop代理之ProxyFactory

    转发地址:https://www.iteye.com/blog/elim-2397388 编程式的创建Aop代理之ProxyFactory Spring Aop是基于代理的,ProxyFactory是 ...

  8. 曹工说Spring Boot源码(19)-- Spring 带给我们的工具利器,创建代理不用愁(ProxyFactory)

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...

  9. 曹工说Spring Boot源码(21)-- 为了让大家理解Spring Aop利器ProxyFactory,我已经拼了

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...

随机推荐

  1. C# 字符串加密解密方法

    这个是加密的算法的命名空间,使用加密算法前要引用该程序集  System.Security.Cryptography using System;using System.Data;using Syst ...

  2. SharePoint2013切换帐户登录菜单

    SharePoint2013帐户姓名显示的地方没有切换帐户的菜单,这个功能对于终端用户是可有可无的,但对于sharepoint管理员或sharepoint开发人员来讲,却是一个很重要的菜单,由于经常要 ...

  3. .NET中各种不同的Timer之间区别

    System.Timer.Timer 根据命名空间看这个类貌似才是标准的Timer,它提供Interval属性和Elapsed事件.可以每隔一个时间周期触发一次Elapsed事件.在ThreadPoo ...

  4. Java中的protected访问修饰符

    在某个类中定义的protected 方法和属性和默认权限方法和属性是一样的.比如,某类的protected 方法和属性在包外是不能通过该类实例进行访问的(你能在包外访问一个类的默认权限的方法和属性吗? ...

  5. 关于广义后缀树(多串SAM)的总结

    之前我们给的SAM的例题,基本上是一个串建SAM的就能做的 如果要建多个串的SAM应该怎么做呢 首先看题,bzoj2780 我一开始的想法是SA以前的弄法,把串拼起来,中间加分隔符做SAM 这题确实可 ...

  6. poj3281

    非常非常经典的构图 有二分图学习基础的话,很容易想到这是一个“三分图”的匹配问题 我们将牛,food,drink作为点 为了方便,我们将牛放在中间,每头牛的出边指向drink种类,入边由food指入 ...

  7. 完全用xml实现imageview点击换一张图片

    <ImageView android:layout_width="60dp" android:layout_height="60dp" android:b ...

  8. Java [Leetcode 273]Delete Node in a Linked List

    题目描述: Write a function to delete a node (except the tail) in a singly linked list, given only access ...

  9. WCF发布后远程访问的域名解析问题

    环境: VS2010 sp1,.net framework 4.0,windows server 2003 x64 ,iis 6.0 症状: WCF开发测试,本地调用都正常.发布后,在浏览器中访问ht ...

  10. 求大于整数m且紧靠m的k个素数 及 判断一个数是否为素数的方法

    题目: 请编写一个函数void fun(int m,int k ,int xx[]),该函数的功能是:将大于整数m且紧靠m的k个素数存入xx所指的数组中. 例如,若输入:17,5,则应输出:19,23 ...