gpt4 book ai didi

java - 如何在 Spring 配置文件中混合使用 CGLIB 和 JDK 代理?

转载 作者:搜寻专家 更新时间:2023-10-31 19:48:31 25 4
gpt4 key购买 nike

此线程与我遇到的问题有关 here regarding the needs for access to protected methods of an advised class .我正在使用 Spring 3.0.6,并创建了一个 Spring 分析方面,我正在使用 JDK 代理将其应用于大量 bean。

但是,由于需要访问一个特定 bean 中的 protected 方法,我建议使用 CGLIB。我想继续使用 JDK 代理的所有其他 bean。

我混合使用注释和 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 Proxying mechanisms官方文档:

Note

Multiple <aop:config/> sections are collapsed into a single unified auto-proxy creator at runtime, which applies the strongest proxy settings that any of the <aop:config/> sections (typically from different XML bean definition files) specified. This also applies to the <tx:annotation-driven/> and <aop:aspectj-autoproxy/> elements.

To be clear: using 'proxy-target-class="true"' on <tx:annotation-driven/>, <aop:aspectj-autoproxy/> or <aop:config/> elements will force the use of CGLIB proxies for all three of them.

关于java - 如何在 Spring 配置文件中混合使用 CGLIB 和 JDK 代理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10110569/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com