How to mix CGLIB and JDK proxies in Spring configuration files?

This thread is related to the problem that I am facing here regarding the need for access to the protected methods of the recommended class . I am using Spring 3.0.6 and have created a Spring profiling aspect that I apply to a significant number of beans using the JDK proxy.

However, due to the need to access protected methods in one specific bean, I would like to recommend it using CGLIB. All other beans I would like to continue to use JDK Proxies.

I use a combination of annotations and xml configuration, but this particular aspect is defined in the XML configuration.

I know that there is a <aop:scoped-proxy> , but from what I can say, it applies to all aspects.

Is there any way to determine for one aspect the use of CGLIB instead?

 <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> 

I tried to split the configuration into two parts, and for one configuration specify target-class="true" and another target-class="false" , but it seems that CGLIB will apply to everyone at this point.

Is there any way to do this?

Thanks,

Eric

+5
source share
1 answer

Unfortunately, either all or none of the beans use CGLIB, and if you use target class proxying in one place, it is forced in all other places. Quoting 8.6 Proxying mechanisms for official documentation:

Note

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

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

+7
source

Source: https://habr.com/ru/post/920780/


All Articles