[英]How to mix CGLIB and JDK proxies in Spring configuration files?
這個線程與我在這里遇到的有關訪問受建議類的受保護方法的需求有關 。 我正在使用Spring 3.0.6,並創建了一個Spring分析方面,我正在使用JDK代理應用於大量的bean。
但是,由於需要訪問一個特定bean中的受保護方法,我想使用CGLIB建議它。 所有其他bean我想繼續使用JDK Proxies。
我使用了注釋和xml配置的混合,但這個特定方面是在XML配置中定義的。
我知道有<aop:scoped-proxy>
標簽,但據我所知,這適用於所有方面。
無論如何要定義單個方面來使用CGLIB嗎?
<aop:config>
<aop:aspect id="Profiler" ref="lendingSimulationServiceProfilerInterceptor">
<!-- info -->
<aop:around method="infoProfiler"
pointcut="execution(* com.cws.cs.lendingsimulationservice.service.LendingSimulationServiceImpl.calculate*(..))" />
<!-- debug -->
<aop:around method="infoProfiler"
pointcut="execution(* com.cws.cs.lendingsimulationservice.process.LendingSimulationProcessImpl.calculate(..))" />
<aop:around method="infoProfiler"
pointcut="execution(* com.blaze.BlazeEngine.invokeService(..))" />
<!-- trace -->
<aop:around method="traceProfiler"
pointcut="execution(* com.calculator.dao.impl.LendingSimulationDaoImpl.*(..))" />
<!-- NEED TO DEFINE THIS PARTICULAR ASPECT AS CGLIB -->
<aop:around method="traceProfiler"
pointcut="execution(* com.cws.cs.lendingsimulationservice.util.pool.JAXBPoolImpl.*(..))" />
</aop:aspect>
</aop:config>
我試圖將配置拆分為兩個,並且對於一個配置指定target-class="true"
而另一個target-class="false"
,但它似乎在那時將CGLIB應用於所有人。
有沒有辦法實現這個目標?
謝謝,
埃里克
不幸的是,全部或沒有bean都使用CGLIB,如果你在一個地方使用目標類的代理,它會被強制在所有其他地方。 引用8.6官方文件的代理機制 :
注意
多個
<aop:config/>
部分在運行時折疊為單個統一的自動代理創建器,它應用指定的任何<aop:config/>
部分(通常來自不同的XML bean定義文件)的最強代理設置。 這也適用於<tx:annotation-driven/>
和<aop:aspectj-autoproxy/>
元素。需要明確的是:在使用
'proxy-target-class="true"'
上<tx:annotation-driven/>
<aop:aspectj-autoproxy/>
或<aop:config/>
元素將強制使用CGLIB代理為他們三個 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.