2012-01-20 76 views
2

我有兩個項目(客戶端和服務器)試圖通過Eclipse Helios中的Spring RMI交換一些對象。客戶端只知道他們的接口。傳遞字符串的類似程序工作正常。使用Spring RMI的ClassNotFoundException

我下面春天在行動的第三版例子和,而不是Spitter首選Twitter的:)的對象在服務器正常工作,也沒有人知道的實現,只是春天。奇怪的是,它拋出了ClassNotFoundException異常,似乎客戶抱怨他不知道TwitterImpl!

在此先感謝您的幫助!

堆棧跟蹤:

Exception in thread "main" org.springframework.remoting.RemoteAccessException: Could not access remote service [rmi://localhost/TwitterService]; 
nested exception is java.rmi.UnmarshalException: error unmarshalling return; nested exception is: 
java.lang.ClassNotFoundException: twitter.domain.TwitterImpl (no security manager: RMI class loader disabled) 
at org.springframework.remoting.rmi.RmiClientInterceptorUtils.convertRmiAccessException(RmiClientInterceptorUtils.java:193) 
at org.springframework.remoting.rmi.RmiClientInterceptor.doInvoke(RmiClientInterceptor.java:347) 
at org.springframework.remoting.rmi.RmiClientInterceptor.invoke(RmiClientInterceptor.java:259) 
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) 
at $Proxy1.getTwitter(Unknown Source) 
at twitter.Retrieve.getTwits(Retrieve.java:31) 
at twitter.Main.main(Main.java:30) 

客戶rmi.xml

<bean class="org.springframework.remoting.rmi.RmiProxyFactoryBean" 
    id="twitterService"> 
<property name="serviceUrl" 
    value="rmi://localhost/TwitterService"> 
</property> 
<property name="serviceInterface" 
    value="twitter.service.TwitterService"> 
</property> 


</bean> 
<bean id="retrieve" class="twitter.Retrieve"> 
    <property name="twitterService" ref="twitterService"></property> 
</bean> 

服務器rmi.xml

<bean class="org.springframework.remoting.rmi.RmiServiceExporter"> 
    <property name="service" ref="twitterService" /> 
    <property name="serviceName" value="TwitterService" /> 
    <property name="serviceInterface" value="twitter.service.TwitterService" /> 
</bean> 
<bean class="twitter.service.TwitterServiceImpl" id="twitterService"> 
    <property name="twits"> 
     ... 
    </property> 
    <property name="twitters"> 
     ... 
    </property> 
</bean> 

回答

3

我noobily誤解RMI的概念。我認爲客戶端甚至不應該知道類的實現,從服務器接收字節碼。實際上,遠程處理的目的是訪問遠程對象的狀態,客戶端需要知道實現。拋出ClassNotFound異常並不奇怪。

+0

+1「noobily」 –