现在的位置: 首页 > 综合 > 正文

Spring 使用AOP导致IOC注入失败

2013年08月06日 ⁄ 综合 ⁄ 共 1465字 ⁄ 字号 评论关闭

前几天把权限系统重构了,服务层针对前后台分别提供相应的接口,但在配置注入的时候出现如下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sysCurrentSessionService' defined in ServletContext resource [/WEB-INF/servicecontext/sysUserContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy1 implementing com.centerm.service.rightmanage.ISysUserService,com.centerm.service.rightmanage.ISysUser4Dwr,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.centerm.service.rightmanage.Impl.SysUserService] for property 'sysUserService'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy1 implementing com.centerm.service.rightmanage.ISysUserService,com.centerm.service.rightmanage.ISysUser4Dwr,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.centerm.service.rightmanage.Impl.SysUserService] for property 'sysUserService': no matching editors or conversion strategy found

上面的英文意思说无法将一个实现com.centerm.service.rightmanage.ISysUserService,com.centerm.service.rightmanage.ISysUser4Dwr,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised接口的代理注入给com.centerm.service.rightmanage.Impl.SysUserService

 

之所以会出现这个问题是:因为我配置了aop拦截了sysUserService对象,Spring依照sysUserService对象生成其接口的代理,当把这接口的代理塞给sysUserService对象出错了

简化下如下:

MyBean implements IBean

ProxyBean implements IBean

myBean=ProxyBean 当然会出错

抱歉!评论已关闭.