【发布时间】:2013-03-20 15:05:48
【问题描述】:
我编写了一个简单的客户端服务器架构,可以帮助我从 MS Office 文档中生成 PDF 文件。通信通过 RMI 处理,Spring 将整个复杂性封装在服务器端。
我不能在客户端使用 Spring,因为我从 Matlab 2007b 调用方法。由于 Matlab 中对静态和动态类路径的特殊处理,依赖于 spring 的 Jar 会产生异常。
长话短说:我用纯 java 写了一个简单的 RMI 客户端:
import com.whatever.PDFCreationService;
Object service = Naming.lookup("rmi://operations:1099/pdfCreationService");
System.out.println((PDFCreationService)service); //produces ClassCastException
界面:
public interface PDFCreationService {
public PDFCreationConfig createPDF(PDFCreationConfig config) throws IOException, InterruptedException, OperationInterruptionException;
}
从我的“前”spring 配置中提取(客户端):
<bean id="pdfCreationService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://operations:1099/pdfCreationService"/>
<property name="serviceInterface" value="com.whatever.creator.PDFCreationService"/>
</bean>
在服务器端:
<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
<property name="serviceName" value="pdfCreationService"/>
<property name="service" ref="pdfCreationService"/>
<property name="serviceInterface" value="com.whatever.creator.PDFCreationService"/>
<!-- defaults to 1099 -->
<property name="registryPort" value="1099"/>
</bean>
当我运行代码时,会抛出以下异常:
Exception in thread "main" java.lang.ClassCastException: $Proxy0 cannot be cast to com.whatever.creator.PDFCreationService
我 100% 确信我不会尝试投到像这篇文章中这样的类:"ClassCastException: $Proxy0 cannot be cast" error while creating simple RMI application
spring 是否将我的接口封装在不同的接口中?有没有办法找出 Proxy 隐藏了哪个接口?
如果您需要更多详细信息来澄清我的问题,请告诉我。
【问题讨论】:
-
那个异常是从哪里抛出的 from ?堆栈跟踪摘录会很好......
-
您的远程接口首先需要扩展 Remote。
标签: spring proxy rmi classcastexception