Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想使用 cglib 作为我的 spring 代理机制。问题是,我有一些 bean 的依赖项由构造函数注入,我无法更改。CGLIB 似乎不太喜欢这样,不会让我实例化那个 bean。有什么办法吗?(例如,我可以为某些 bean 禁用 cglib 代理吗?或者更好的是,我可以让 CGLIB 代理这些 bean 吗?)
提前发送
一个简短的回答是您不能代理此类 bean。请参阅SPR-3150 jira 问题。
由于 Eugene 的简短回答可能是正确的,因此另一种方法是使用适配器或装饰器模式,使用组合而不是继承。代理您的装饰器,并让它具有原始 bean 作为依赖项。
或者做明智的事情并切换到基于接口的代理。