2012-12-15 43 views
2

而發展中國家低於春季RMI的應用程序,我收到以下錯誤是代碼..在春季得到錯誤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.[email protected]70eb7859: display name [org.[email protected]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.[email protected]70eb7859]: org.s[email protected]28bb0d0d 
15 Dec, 2012 5:01:10 PM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons 
INFO: Pre-instantiating singletons in org.s[email protected]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.s[email protected]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 

回答

2

根源:拋出java.lang.ClassNotFoundException:EasyServer

接口EasyServer是包com.tcs

你可能想嘗試

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

非常感謝它的工作原理.. !! – user1906154