Spring Transaction - 代理混淆 [英] Spring Transaction - Proxy confusion

查看:71
本文介绍了Spring Transaction - 代理混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 <tx:advice id="txAdvice" transaction-manager="jtaTxManager">
  <tx:attributes>
   <tx:method name="*" />
  </tx:attributes>
 </tx:advice>

 <aop:config proxy-target-class="true">
  <aop:pointcut id="fooServiceOperation"
   expression="execution(* x.y.SampClass.save(..))" />
  <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation" />
 </aop:config>

 <bean id="Samp1" class=" x.y.SampClass"></bean>

        <bean id="SearchDispatchRpcGwtServlet" class="x.y.server.SearchDispatchRpcGwtServlet">
  <constructor-arg>
       <list>
         <ref bean="webServiceClient"/>                          
       </list>
  </constructor-arg>      
 </bean>

 <!-- Service Clients --> 
 <bean id="webServiceClient" class="x.y.KSBClientProxyFactoryBean">
  <property name="serviceEndpointInterface" value="x.y.service.WebService" />
  <property name="serviceQName" value="{http://x.y.org/wsdl/organization}WebService" />
 </bean>

这是示例弹簧上下文文件的一部分。我正在尝试为 SampClass 创建一个事务建议来执行save方法。

This is the part of sample spring context file. I am trying to create a transaction advice for SampClass to execute on the save method.

所以从我的理解来看应该只为 SampClass 创建一个代理。

So from my understanding it should create a proxy for SampClass only.

我有一个 SearchDispatchRpcGwtServlet 以webservice客户端为参数,客户端本身也是代理服务器。由于它无法创建代理的代理,因此该bean也因某些原因而被代理。

I have a SearchDispatchRpcGwtServlet which takes as an argument a webservice Client which is also a proxy in itself. This bean is also getting proxied for some reason where it fails because it cannot create a proxy of a proxy.

我必须添加 SearchDispatchRpcGwtServlet 创建一个 SampClass 的实例并调用save方法。

I must add that SearchDispatchRpcGwtServlet creates an instance of SampClass and calls the save method.

我得到以下异常:


java.lang.IllegalArgumentException:
无法将最终类类
$ Proxy118子类化为
net。 sf.cglib.proxy.Enhancer.generateClass(Enhancer
.java:446)位于
net.sf.cglib.transform.TransformingClassGenerator。
generateClass(TransformingClassGenerator.java:33)

java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy118 at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer .java:446) at net.sf.cglib.transform.TransformingClassGenerator. generateClass(TransformingClassGenerator.java:33)

我不明白为什么 SearchDispatchRpcGwtServlet 代理正在创建。有人可以解释一下

I dont understand why SearchDispatchRpcGwtServlet proxy is getting created. Can someone explain.

添加堆栈跟踪

Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class $Proxy117]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy117
    at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:213)
    at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:473)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:348)
    at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:309)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:361)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.postProcessObjectFromFactoryBean(AbstractAutowireCapableBeanFactory.java:1427)
    at org.springframework.beans.factory.support.FactoryBeanRegistrySupport$1.run(FactoryBeanRegistrySupport.java:139)
    ... 85 more
Caused by: java.lang.IllegalArgumentException: Cannot subclass final class class $Proxy117
    at net.sf.cglib.proxy.Enhancer.generateClass(Enhancer.java:446)
    at net.sf.cglib.transform.TransformingClassGenerator.generateClass(TransformingClassGenerator.java:33)
    at net.sf.cglib.core.DefaultGeneratorStrategy.generate(DefaultGeneratorStrategy.java:25)
    at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:216)
    at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
    at net.sf.cglib.proxy.Enhancer.create(Enhancer.java:285)
    at org.springframework.aop.framework.Cglib2AopProxy.getProxy(Cglib2AopProxy.java:201)


推荐答案

AbstractAutoProxyCreator的子类正在尝试代理bean,但该bean本身已经是使用其他机制创建的CGLIB代理,例如 aop:config proxy-target-class =true

a subclass of AbstractAutoProxyCreator is trying to proxy a bean, but that bean is already itself a CGLIB proxy created using another mechanism such as aop:config proxy-target-class="true.

为避免这种情况,请确保避免为同一个bean混合使用不同的方面编织机制(ProxyBeanFactory和aop:config)。

To avoid this, make sure to avoid mixing the different aspect weaving mechanisms (ProxyBeanFactory and aop:config ) for the same bean.

在这种情况下,交易方面也可以通过<$ c $&$ tx:annotation:driven /> 通过<$ c $编织c> @Transactional 注释。

In this case the transaction aspects can also be weaved via <tx:annotation:driven/> via the @Transactional annotation.

或者可以从bean中删除自动装配/扫描并通过XML注入依赖项使用setter。

Alternatively it would be possible to remove the autowiring/scan from the bean and do the injection of dependencies via XML using setters.

另一种方法是通过声明< context:load-time-weaver /> 并添加所需的罐子。

Another alternative is to use load time weaving everywhere by declaring <context:load-time-weaver/> and adding the needed jars.

还要看看这个发布,它一般会是最好只使用一种方法在整个应用程序中应用方面,以避免这个问题。

Have a look also at this post, it general it would be better to use only one one way of applying the aspects in the whole application, in order to avoid this problem.

这篇关于Spring Transaction - 代理混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆