Tag: proxy classes

spring,如何更改cglib命名策略

当spring创建代理时,它使用带有默认命名策略的cglib。 有没有办法改变命名政策? 生成的类名与我使用的另一个框架冲突。

Java / JSF / Tomcat / Spring – Proxy-Object与原始对象有不同的方法

今天我遇到了这个问题,这真的让我感到困扰,因为几乎代码已经运行了(并且即使在恢复到旧版本之后也停止了工作)。 我正在Facelets-Page上访问一个Spring-Bean。 Spring在Proxies中包装这些对象以使用方面和其他一些东西。 问题是,我在尝试访问bean的属性时遇到exception。 例外是这样的: javax.el.PropertyNotFoundException: /customers.xhtml @23,27 value=”#{customerBean.customer}”: Property ‘customer’ not found on type $Proxy88 我肯定知道(!!)有相应的getter / setter方法。 到目前为止我尝试的事情: 将应用程序部署到另一个tomcat安装 清除所有tomcat-caches,webapp目录 清理eclipse项目 使用javap(以及那里的方法/属性)检查相应的方法 更改bean的范围 更改bean的类名 更改spring bean-id 更改bean的serialVersionUID 无论我做什么,类都不正确地被类加载器正确包装或者没有正确加载。 有谁知道什么可能导致这样的问题? 我不知道该怎么做,所以任何建议都非常感谢! 提前致谢! 问候,罗伯特

如何在scala中使用java代理

我有一个Iface接口,它有两个用java编写的方法。 该接口是Zzz类的内部接口。 我在scala中编写了调用处理程序。 然后我尝试在scala中创建一个新的代理实例,如下所示。 val handler = new ProxyInvocationHandler // this handler implements //InvocationHandler interface val impl = Proxy.newProxyInstance( Class.forName(classOf[Iface].getName).getClassLoader(), Class.forName(classOf[Iface].getName).getClasses, handler ).asInstanceOf[Iface] 但是编译器在这里说 $Proxy0 cannot be cast to xxx.yyy.Zzz$Iface 我怎样才能以简短的方式使用代理。

如何创建一个我无法更改的类,实现一个接口?

我有一个来自另一个闭源的库的类,但我希望能够使用它的接口。 原因是我不想在任何地方进行instanceof检查或null -checks,但我也不想扩展现有的类。 例如,假设我有这个代码: public class Example { // QuietFoo is from another library that I can’t change private static QuietFoo quietFoo; // LoudFoo is my own code and is meant to replace QuietFoo private static LoudFoo loudFoo; public static void main(String[] args) { handle(foo); } private static void handle(Object foo) { if (foo instanceof […]

在非单例bean上修复Spring代理上的BeanNotOfRequiredTypeException?

我在从应用程序上下文中提取Spring bean时遇到问题。 当我尝试; InnerThread instance = (InnerThread) SpringContextFactory.getApplicationContext().getBean(“innerThread”, InnerThread.class); 我明白了 org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named ‘innerThread’ must be of type [com.generic.InnerThread], but was actually of type [$Proxy26] 如果没有getBean()调用中的指定类,我会得到一个ClassCastException(您可以在下面详细介绍)。 InnerThread bean被初始化为非单例,因为我需要多个实例。 InnerThread类还扩展了Thread。 有趣的是,这个错误出现在OuterThread中,它的设置方式与InnerThread完全相同。 我试图在下面包含所有相关的代码清单/堆栈跟踪。 有更多Spring体验的人可以告诉我这里发生了什么吗? 代码/配置清单 OuterThread.java片段: public class OuterThread extends Thread { private Queue createInnerThreads() { Queue threads = new ArrayBlockingQueue(); ApplicationContext ctx = SpringContextFactory.getApplicationContext(); int i […]