开发者社区> 问答> 正文

spring强制cglib代理不起作用?附异常信息?报错

配置了强制使用cglib,但spring还是使用JDK代理service,所有的service都实现了IGenericService接口,而且在有注入bean的地方,会报错

Cannot convert value of type [$Proxy10 implementing org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,net.sf.cglib.proxy.Factory,com.xxx.service.IGenericService] to required type [com.xxx.service.impl.UserService] for property 'userService': no matching editors or conversion strategy found

aop的配置:使用的是cglib-nodep-2.1_3.jar,spring3.1.4

<aop:aspectj-autoproxy proxy-target-class="true"/>  

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<property name="dataSource">
<ref bean="dataSource" />
</property>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
       <tx:method name="get*" read-only="true" />
       <tx:method name="find*" read-only="true" />
       <tx:method name="*" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
    <aop:config proxy-target-class="true" >
<aop:pointcut id="serviceMethod"
expression="execution(* com.xxx.service.impl..*Service.*(..))" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod" />
</aop:config>

折腾一天了,不知道问题出在哪里,求指点

异常信息:

Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type '$Proxy10 implementing org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,net.sf.cglib.proxy.Factory,xxxxx.service.IGenericService' to required type 'xxxx.service.impl.UserService' for property 'userService'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [$Proxy10 implementing org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,net.sf.cglib.proxy.Factory,xxxxx.service.IGenericService] to required type [xxxxx.service.impl.UserService] for property 'userService': no matching editors or conversion strategy found
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:485)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:516)
at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:510)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1406)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1365)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1118)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
... 88 more
Caused by: java.lang.IllegalStateException: Cannot convert value of type [$Proxy10 implementing org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised,net.sf.cglib.proxy.Factory,xxxxx.service.IGenericService] to required type [xxxx.service.impl.UserService] for property 'userService': no matching editors or conversion strategy found
at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:247)
at org.springframework.beans.BeanWrapperImpl.convertIfNecessary(BeanWrapperImpl.java:470)
... 94 more


展开
收起
爱吃鱼的程序员 2020-06-22 18:59:59 655 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    找到问题了,是配置了shiro的关系,得到shiro区提问了

    2020-06-22 19:00:15
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载

相关实验场景

更多