标签:spring proxy aop cglib interface
今天,在项目中遇到一个问题,情况是这样的:在一个项目中,我配置了一个用以处理任务的工厂类,然后将这个工厂类注入到其他的service类中进行使用。在Spring中的配置如下:
<bean id="linkingDetectService" class="cn.vobile.service.linkingdetect.LinkingDetectServiceImpl"> <property name="taskPriority" value="normal" /> <property name="commonTaskService" ref="commonTaskService" /> <property name="gson" ref="gson" /> </bean> <bean id="reclaimMatchSubscriptionService" class="cn.vobile.service.matchsubscription.reclaim.ReclaimMatchSubscriptionServiceImpl"> <property name="taskPriority" value="normal" /> <property name="matchSubscriptionService" ref="matchSubscriptionService"/> <property name="gson" ref="gson" /> <property name="matchedVideoService" ref="matchedVideoCommonService" /> <property name="transactionTemplate" ref="masterTransactionTemplate" /> </bean> <bean id="commonTaskFactory" class="cn.vobile.service.commontask.CommonTaskFactory"> <property name="serviceMap"> <map> <entry key="linkingDetect"><ref local="linkingDetectService"/></entry> <entry key="reclaimMatchSubscription"><ref local="reclaimMatchSubscriptionService"/></entry> </map> </property> </bean>结果在项目其中的时候就报了一个配置错误,如下所示:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'matchedVideoService' defined in ServletContext resource [/WEB-INF/classes/applicationServiceContext.xml]: Cannot resolve reference to bean 'commonTaskFactory' while setting bean property 'commonTaskFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonTaskFactory' defined in ServletContext resource [/WEB-INF/classes/applicationServiceContext.xml]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Cannot proxy target class because CGLIB2 is not available. Add CGLIB to the class path or specify proxy interfaces.
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <bean id="masterTransactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> <property name="transactionManager" ref="txManager" /> </bean> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="get*" propagation="SUPPORTS" read-only="true" timeout="20"/> <tx:method name="is*" propagation="SUPPORTS" read-only="true" timeout="20"/> <tx:method name="has*" propagation="SUPPORTS" read-only="true" timeout="20"/> <tx:method name="exist*" propagation="SUPPORTS" read-only="true" timeout="20"/> <tx:method name="*" /> </tx:attributes> </tx:advice> <aop:config> <aop:pointcut id="vtServiceTransaction" expression="execution(* cn.vobile.service.*.*.*(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="vtServiceTransaction" /> </aop:config>
解决方案一:引入CGLIB的jar包。
解决方案二:把这里的***Factory类从事务层挪出去,这样就不会调用JDK的动态代理了。
标签:spring proxy aop cglib interface
原文地址:http://blog.csdn.net/thjnemo/article/details/42170957