【问题标题】:ClassNotFoundException using Spring RMI使用 Spring RMI 的 ClassNotFoundException
【发布时间】:2012-01-20 19:58:52
【问题描述】:

我有两个项目(客户端和服务器)试图通过 Eclipse Helios 中的 Spring RMI 交换一些对象。客户端只知道他们的接口。传递字符串的类似程序可以正常工作。

我正在关注 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>

【问题讨论】:

    标签: java spring rmi


    【解决方案1】:

    我完全误解了 RMI 的概念。我认为客户端甚至不应该知道类实现,从服务器接收字节码。实际上,远程处理的目的是访问远程对象的状态,客户端需要知道实现。抛出 ClassNotFound 异常并不奇怪。

    【讨论】:

      猜你喜欢
      • 2011-11-15
      • 2014-06-14
      • 2016-06-15
      • 2012-07-01
      • 2023-03-21
      • 1970-01-01
      • 2017-01-16
      相关资源
      最近更新 更多