我有两个项目(客户端和服务器)试图通过Eclipse Helios中的Spring RMI交换一些对象。客户端只知道他们的接口。通过Strings的类似程序运行正常。
我正在关注 Spring In Action 的第3版示例,而不是Spitter首选Twitter :)对象在服务器上工作正常,没有人知道实现,只有Spring。奇怪的是,它抛出一个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>
答案 0 :(得分:4)
我愚蠢地误解了RMI的概念。我认为客户端甚至不应该知道类实现,从服务器接收字节码。实际上,远程处理的目的是访问远程对象的状态,客户端需要知道实现。抛出ClassNotFound异常并不奇怪。