`
zhangyi6678
  • 浏览: 76463 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

spring ProxyFactoryBean什么时候需要配置proxyTargetClass

    博客分类:
  • java
阅读更多

spring ProxyFactoryBean什么时候需要配置proxyTargetClass

比如现在有这样一段代码:
<bean id="ttransactionDefinition" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" abstract="true">
        <property name="transactionManager">
            <ref bean="transactionManager" />
        </property>
        <property name="transactionAttributeSource">
            <ref bean="txAttributeSource" />
        </property>
</bean>

<bean id="test" parent="ttransactionDefinition">
 <property name="proxyTargetClass" value="true"></property>
 <property name="target">
  <bean class="com.alibaba.intl.biz.escrow.message.TestTram" />
 </property>
</bean>

<bean id ="testProxyCls" class="com.wolf.TestProxyClass">
 <property name="test" bean="test"/>
</bean>
proxyTargetClass需要配置的情况只有一种:
  当TestTram类有实现某个接口,而TestProxyClass类中配置的类对象是TestTram时(而不是TestTram实现的接口),这时候你需要配置proxyTargetClass=true
 
  如果TestTram没有实现某个接口,而TestProxyClass类中配置的类对象是TestTram,这个时候我们是不需要配置proxyTargetClass=true的.(使用cgilib来动态代理)
  如果TestTram实现某个接口, 而TestProxyClass类中配置的是TestTram实现的interface的话.那样我既不需要配置proxyInterface,也不需要配置proxyTargetClass

 
 为什么我们在没有配置proxyInterface情况下,去配置proxyTargetClass.因为spring会去拿到当前配置的target实现的所有接口,然后通过动态代理出类.
 
 可以看看spring的这段代码:(AbstractSingletonProxyFactoryBean类)
  if (this.proxyInterfaces != null) {
   proxyFactory.setInterfaces(this.proxyInterfaces);
  }
  else if (!isProxyTargetClass()) {
   // Rely on AOP infrastructure to tell us what interfaces to proxy.
   proxyFactory.setInterfaces(ClassUtils.getAllInterfacesForClass(targetSource.getTargetClass()));
  }
  this.proxy = getProxy(proxyFactory);

分享到:
评论

相关推荐

    Spring AOP 源码系列:ProxyFactoryBean

    NULL 博文链接:https://czj4451.iteye.com/blog/2051461

    SpringBootAopInterceptor:Spring Boot ProxyFactoryBean

    SpringBootAopInterceptor Spring Boot ProxyFactoryBean

    Spring基于ProxyFactoryBean创建AOP代理

    主要介绍了Spring基于ProxyFactoryBean创建AOP代理,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

    spring-aop-ProxyFactoryBean 源码分析

    NULL 博文链接:https://wangxinchun.iteye.com/blog/2079585

    Spring-Reference_zh_CN(Spring中文参考手册)

    6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. 其它资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点实施 ...

    Spring 2.0 开发参考手册

    6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. 其它资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点...

    spring aop 实现源代码--xml and annotation(带lib包)

    &lt;bean id="messageSender" class="org.springframework.aop.framework.ProxyFactoryBean"&gt; 12. &lt;property name="proxyInterfaces" value="com.savage.aop.MessageSender"/&gt; 13. &lt;property name="target" ref=...

    Spring实现AOP的四种方式

    1. 配置ProxyFactoryBean,显式地设置advisors, advice, target等(基于代理的AOP ) 2. 配置AutoProxyCreator,这种方式下,还是如以前一样使用定义的bean,但是从容器中获得的其实已经是代理对象 3. 通过来配置...

    Spring中文帮助文档

    6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点运算 ...

    spring chm文档

    6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ Load-time weaving(LTW) 6.9. 其它资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点...

    Spring API

    6.8.3. 使用Spring IoC来配置AspectJ的切面 6.8.4. 在Spring应用中使用AspectJ加载时织入(LTW) 6.9. 更多资源 7. Spring AOP APIs 7.1. 简介 7.2. Spring中的切入点API 7.2.1. 概念 7.2.2. 切入点运算 ...

    Spring

    class="org.springframework.aop.framework.ProxyFactoryBean"&gt; &lt;!--这里的必须要指定接口 --&gt; &lt;value&gt;org.nitpro.aop.BizInterface &lt;!--业务处理节点名称和拦截器名称必须都要定义, 必须将拦截器的对象...

    spring in action英文版

     1.1 为什么使用Spring  1.1.1 J2EE开发者的一天  1.1.2 Spring的承诺  1.2 Spring是什么  1.3 开始Spring之旅  1.4 理解反向控制  1.4.1 依赖注入  1.4.2 IoC应用  1.4.3 企业级应用中的...

    Spring in Action(第2版)中文版

    1.1spring是什么 1.2开始spring之旅 1.3理解依赖注入 1.3.1依赖注入 1.3.2di应用 1.3.3企业级应用中的依赖注入 1.4应用aop 1.4.1aop介绍 1.4.2aop使用 1.5小结 第2章基本bean装配 2.1容纳你的bean 2.1.1...

    Spring in Action(第二版 中文高清版).part2

    1.1 Spring是什么 1.2 开始Spring之旅 1.3 理解依赖注入 1.3.1 依赖注入 1.3.2 DI应用 1.3.3 企业级应用中的依赖注入 1.4 应用AOP 1.4.1 AOP介绍 1.4.2 AOP使用 1.5 小结 第2章 基本Bean装配 2.1 容纳...

    Spring in Action(第二版 中文高清版).part1

    1.1 Spring是什么 1.2 开始Spring之旅 1.3 理解依赖注入 1.3.1 依赖注入 1.3.2 DI应用 1.3.3 企业级应用中的依赖注入 1.4 应用AOP 1.4.1 AOP介绍 1.4.2 AOP使用 1.5 小结 第2章 基本Bean装配 2.1 容纳...

    spring-xmemcached

    &lt;bean id="cacheProxyFactoryBean" class="org.springframework.aop.framework.ProxyFactoryBean"&gt; &lt;value&gt;cacheBeforeAdvice &lt;value&gt;cacheAfterAdvice &lt;value&gt;cacheInterceptor&lt;/value&gt; ...

    SPRING API 2.0.CHM

    ProxyFactoryBean ProxyMethodInvocation QuartzJobBean QuickTargetSourceCreator RadioButtonTag RdbmsOperation ReaderContext ReaderEventListener RecordCreator RecordExtractor ...

    spring aop代理列子

    package com.gc.aop下为:aop方式ProxyFactoryBean代理 package com.gc.aop下为:aop方式ProxyFactoryBean代理 package com.gc.autoproxy下为:aop方式自动代理 package com.gc.cglib下为:aop方式cglib代理 ...

    Spring 自动代理创建器详细介绍及简单实例

    在经典的Spring Aop中,Spring提供了自动代理创建器(Aotu proxy creator),有了自动代理创建器,就不再需要使用ProxyFactoryBean手工地创建代理了。 接口Animal和Book:  package com.zzj.aop; public ...

Global site tag (gtag.js) - Google Analytics