spring aop 配置class的异常

在使用spring进行ioc配置aop的时候,我们通常是对接口进行编程的,属性的注入是接口。但如果由于某些原因,我们需要将class注入的时候,我们就会得到一个异常:

java 代码
  1. PropertyAccessException 1: org.springframework.beans.TypeMismatchException: Fail   
  2. ed to convert property value of type [$Proxy7] to required type [org.appfuse.net   
  3. bar.service.impl.NetBarManagerImpl] for property 'netBarManager'; nested excepti   
  4. on is java.lang.IllegalArgumentException: No matching editors or conversion stra   
  5. tegy found  

 

查阅一下资料发现,这是由于java的AOP机制造成的。spring-reference有如下说明:

Spring AOP uses either JDK dynamic proxies or CGLIB to create the proxy for a given target object. (JDK
dynamic proxies are preferred whenever you have a choice).

由于jdk dynamic proxies是对接口进行的,因此无法对实体类进行正常的proxy。解决方法配置proxyTargetClass="true",可以参见下面的链接:

http://www.cwinters.com/news/display/3410

对于spring2的aop配置如下:

<aop:config proxy-target-class="true">
xml 代码
  1. <aop:config proxy-target-class="true">  
  2. <!-- other beans defined here... -->  
  3. </aop:config>  
</aop:config>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值