- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
此线程与我遇到的问题有关 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/
Spring不包含cglib依赖,cglib和spring cglib都有Enhancer类,一个是net.sf.cglib.proxy.Enhancer,另一个是org.springframewor
我正在尝试构建一个大型项目,但由于以下错误而失败: [INFO] -------------------------------------------------------------------
关闭。这个问题不符合 Stack Overflow guidelines 。它目前不接受答案。 想改善这个问题吗?更新问题,以便堆栈溢出为 on-topic。 7年前关闭。 Improve this
@Service public class TestService{ @DynamicReference private ITestProvider testProvider;
我有以下通用 cglib 方法拦截器实现: public class EntityInterceptor implements MethodInterceptor{ private Entit
假设我有一些 A 类,它具有 B 类的属性。 public class ClassA{ private ClassB classB; public ClassA(ClassB classB){ th
我正在使用 CGLib 来增强 A 类。 public class A { public void printName(){ System.out.println("guy");
我的 Controller 在其属性上使用了 @Value 注释,但是发生了一些奇怪的事情: 08:20:31.400 [main] ERROR Controller - postConstruct(
我想做的是序列化一个类实现一个命令模式,以便我稍后可以运行它。在最好的在所有世界中,我想序列化一个匿名类(我是意识到这个问题) 让事情变得有点复杂的是我在 Spring 的环境中并且我希望序列化的匿名
谁能给我一个 Java CGLib 的好例子 Mixin类用法?我一直在挖掘它们似乎都不够简单。 最佳答案 很简单: import static org.junit.Assert.*; import
在实际项目中,考虑到不同的数据使用者,我们经常要处理 VO、DTO、Entity、DO 等对象的转换,如果手动编写 setter/getter 方法一个个赋值,将非常繁琐且难维护。通常情况下,这类转换
代码如下: Patient patient = factory.createPatient(); Enhancer enhancer = new Enhancer(
我有两个类 @Component @Scope(proxyMode=ScopedProxyMode.TARGET_CLASS,value="session") public clas
代码是用 Scala 编写的,但希望 Java 程序员也能理解。 我有以下类(class): class SampleClass { def test(in: String) = "Hello w
我无法为 HttpURLConnection 类创建动态代理,因为它没有公共(public)构造函数来创建增强器。根据要求,我想创建一个动态代理以在运行时获取当前连接的详细信息。 我尝试使用this教
我想使用 cglib 作为我的 spring 代理机制。问题是,我有一些 bean 的依赖项由构造函数注入(inject),我无法更改。 CGLIB 似乎不太喜欢这样,不会让我实例化那个 bean。有
当尝试将 CGLIB 与回调过滤器(在数万个对象上)一起使用时,我注意到速度很糟糕,但我无法找到有关优化 CGLIB 的任何信息。 对于搜索/列表界面,系统从优化的查询中加载多个属性,并使用这些属性填
我正在为生产 spring batch 项目构建端到端测试框架。我们想使用内存中的嵌入式数据库(在我们的例子中是 hsqldb)进行这些测试,因为它运行得更快并且没有环境限制。由于这些数据库引擎之间的
借助 cglib,我可以使用以下代码创建延迟实例化的 BigInteger: Enhancer enhancer = new Enhancer(); enhancer.setSuperclass(Bi
我有一个正在开发的 Java 库,它使用 cglib 创建库用户提供的抽象类的子类,并提供自动生成的用户留在其中的抽象方法的实现。 我的问题是,如果有问题的方法具有包本地(即默认)可访问性,我生成的方
我是一名优秀的程序员,十分优秀!