spring - Spring RMI 出现错误

标签 spring rmi

我在开发 Spring RMI 应用程序时遇到以下错误,下面是代码..

可序列化的类..

 package co.tcs.pojo;
    import java.io.Serializable;      
    public class Message implements Serializable {
         private final String message;    
         public Message(String message) { this.message = message; }    
         public String getMessage() { return message; } 
        }

界面...

package com.tcs;
import co.tcs.pojo.Message;

interface EasyServer {
     Message exchangeMessage(String user);
    }

实现类和服务器类也...

  package com.tcs;
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    import org.springframework.context.support.FileSystemXmlApplicationContext;

    import co.tcs.pojo.Message;    
    public class EasyServerImpl implements EasyServer {    
         public Message exchangeMessage(String user) {
             return new Message(user + ", Spring rocks!");
         }    
         public static void main(String[] args) {    
             try{
                    ApplicationContext appctx=new FileSystemXmlApplicationContext("src/SpringContainer.xml");                   
                    System.out.println("RMI Server started.....>>");
                }
                catch(Exception e)
                {
                    System.out.println("Exception : ServerProgram : main() : ");                    System.out.println("----->");
                    e.printStackTrace();
                    System.out.println("<-----");               }
         }
        }

最后是 xml ..

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">


    <bean id="easyServer" class="com.tcs.EasyServerImpl">
</bean>

<bean class="org.springframework.remoting.rmi.RmiServiceExporter">
 <!-- register the impl as the 'easyServerService' -->
 <property name="serviceName" value="easyServerService"/>
 <property name="service" ref="easyServer"/>
 <property name="serviceInterface" value="EasyServer"/>
 <!-- defaults to 1099 -->
 <property name="registryPort" value="1199"/>
</bean>

</beans>

封装结构快照..

http://imageshack.us/photo/my-images/607/sd1l.jpg/

我收到的错误是..

15 Dec, 2012 5:01:10 PM org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@70eb7859: display name [org.springframework.context.support.FileSystemXmlApplicationContext@70eb7859]; startup date [Sat Dec 15 17:01:10 IST 2012]; root of context hierarchy
15 Dec, 2012 5:01:10 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from file [D:\Pos2Workspace\ztestRmi\src\SpringContainer.xml]
15 Dec, 2012 5:01:10 PM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.FileSystemXmlApplicationContext@70eb7859]: org.springframework.beans.factory.support.DefaultListableBeanFactory@28bb0d0d
15 Dec, 2012 5:01:10 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@28bb0d0d: defining beans [easyServer,org.springframework.remoting.rmi.RmiServiceExporter#0]; root of factory hierarchy
15 Dec, 2012 5:01:10 PM org.springframework.beans.factory.support.DefaultSingletonBeanRegistry destroySingletons
INFO: Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@28bb0d0d: defining beans [easyServer,org.springframework.remoting.rmi.RmiServiceExporter#0]; root of factory hierarchy
Exception : ServerProgram : main() : 
----->
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.remoting.rmi.RmiServiceExporter#0' defined in file [D:\Pos2Workspace\ztestRmi\src\SpringContainer.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [java.lang.Class] for property 'serviceInterface'; nested exception is java.lang.IllegalArgumentException: Cannot find class [EasyServer]. Root cause: java.lang.ClassNotFoundException: EasyServer
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:485)
    at java.security.AccessController.doPrivileged(Native Method)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:455)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:169)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:248)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:170)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:413)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:735)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:369)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:124)
    at org.springframework.context.support.FileSystemXmlApplicationContext.<init>(FileSystemXmlApplicationContext.java:68)
    at com.tcs.EasyServerImpl.main(EasyServerImpl.java:18)
Caused by: org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [java.lang.Class] for property 'serviceInterface'; nested exception is java.lang.IllegalArgumentException: Cannot find class [EasyServer]. Root cause: java.lang.ClassNotFoundException: EasyServer
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:395)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.convertForProperty(AbstractAutowireCapableBeanFactory.java:1313)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1285)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1042)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539)
    ... 13 more
Caused by: java.lang.IllegalArgumentException: Cannot find class [EasyServer]. Root cause: java.lang.ClassNotFoundException: EasyServer
    at org.springframework.util.ClassUtils.resolveClassName(ClassUtils.java:252)
    at org.springframework.beans.propertyeditors.ClassEditor.setAsText(ClassEditor.java:63)
    at org.springframework.beans.TypeConverterDelegate.doConvertTextValue(TypeConverterDelegate.java:341)
    at org.springframework.beans.TypeConverterDelegate.doConvertValue(TypeConverterDelegate.java:325)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:192)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:138)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:390)
    ... 17 more

最佳答案

根本原因:java.lang.ClassNotFoundException:EasyServer

EasyServer接口(interface)位于com.tcs包中

你可能想尝试

<property name="serviceInterface" value="com.tcs.EasyServer"/>

关于spring - Spring RMI 出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13891857/

相关文章:

html - 通过 Spring 3 JavaMail 创建 MIME 格式的多部分消息 Freemarker 模板

java - 初学者 - Spring/hibernate 集成,asm 不兼容

Java RMI,找不到 stub 类,java.rmi.ServerException : RemoteException occurred in server thread;

Java拒绝访问属性权限

java - 使用 java RMI 传递复合对象

java - 在运行时从另一个类的哈希表中获取值

java - Spring xml 与 java 配置中的类类型注入(inject)

java - Spring Security 配置未得到应用

spring - 注册过滤器时@Bean和@Component的区别?

Tomcat负载均衡环境下Java应用间通信