5

该线程与我在这里遇到的一个问题有关,即需要访问建议类的受保护方法。我正在使用 Spring 3.0.6,并创建了一个 Spring 分析方面,我将其应用于使用 JDK 代理的大量 bean。

但是,由于需要访问一个特定 bean 中的受保护方法,我想建议它使用 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 应用于所有配置。

有没有办法做到这一点?

谢谢,

埃里克

4

1 回答 1

7

不幸的是,所有或没有 bean 都使用 CGLIB,如果您在一个地方使用目标类的代理,则在所有其他地方都强制使用它。引用官方文档的8.6 Proxying机制:

笔记

多个<aop:config/>部分在运行时被折叠成一个统一的自动代理创建器,它应用任何<aop:config/>部分(通常来自不同的 XML bean 定义文件)指定的最强代理设置。这也适用于<tx:annotation-driven/>and<aop:aspectj-autoproxy/>元素。

明确一点:使用'proxy-target-class="true"'on <tx:annotation-driven/><aop:aspectj-autoproxy/>or<aop:config/>元素将强制对所有三个使用 CGLIB 代理。

于 2012-04-11T18:58:27.767 回答