2

我在开发 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
4

1 回答 1

2

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

接口 EasyServer 在 com.tcs 包中

你可能想试试

<property name="serviceInterface" value="com.tcs.EasyServer"/>
于 2012-12-15T11:52:22.553 回答