Announcement Announcement Module
Collapse
No announcement yet.
Could not find RMI service in RMI registry; neste exception is java.rmi.NotBoundExce Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Could not find RMI service in RMI registry; neste exception is java.rmi.NotBoundExce

    Hi,
    I am running simple Spring-RMI using springsource Tool suite. I have taken new Springproject form IDe. In that i have defiend both server as well as cleint and defiend bean configuration separately for both server and client. when i run the project as java application for server i am getting following exception.
    Code:
    INFO: Loading XML bean definitions from class path resource [rmserver.xml]
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'rmserver' defined in class path resource [rmserver.xml]: Invocation of init method failed; nested exception is org.springframework.remoting.RemoteLookupFailureException: Could not find RMI service [rmi://10.105.188.37:1099/rmserver] in RMI registry; nested exception is java.rmi.NotBoundException: rmserver
    Here is my code what i have written.
    Code:
    Server code:
    Interface
    public interface RmServer extends Remote{	
    	public String getResult(String s) throws RemoteException;
    }
    Implementation
    public class RmServerImpl extends UnicastRemoteObject implements RmServer {
    	 RmServer rmServer;	 
    	public void setRmServer(RmServer rmServer) {
    		this.rmServer = rmServer;
    	}
    	protected RmServerImpl() throws RemoteException {
    		System.out.println("Its Ok.....");
    	}	
    	private static final long serialVersionUID = 1L;
        public static void main(String[] args ){
        	try {
        		System.out.println("In Main Method");
    			RmServerImpl rm= new RmServerImpl();
    			Registry registry = LocateRegistry.createRegistry(1099);
                registry.rebind("rmServer", rm);
        		System.out.println("Service is ready Now");
    		} catch (Exception e) {
    			// TODO: handle exception
    		}
        }
    	@Override
    	public String getResult(String s) throws RemoteException {
    		return "Hi VIjay Good Jbo"+s;
    	}
    }
    Calling RMI server
    public class RmSpring {
    	public static void main(String args[]) 
    	   { 
    	  try 
    	  { 
    	   String s=null;
    	   System.out.println("Wait.."); 
    	   Resource   res = new ClassPathResource("rmserver.xml"); 
    	   BeanFactory   factory = new XmlBeanFactory(res); 
    	   RmServer bean1 = (RmServer) factory.getBean("rmserver"); 
    	   String r= bean1.getResult(s) ;
    	   System.out.println(r); 
    	  } 
    	  catch(Exception e1) 
    	  {System.out.println(""+e1);} 
    	   } 
    }
    Client Code interface
    public interface RmService {
    	public String getResult(String s);
    }
    implementation
    public class RmServiceImpl implements RmService {
    	   public static void main(String args[]) 
    	   { 
    	  System.out.println("ready"); 
    	   } 
    	   public RmServiceImpl() 
    	   { 
    	  System.out.println("constructor ok"); 
    	   } 
    	@Override
    	public String getResult(String s) {
    		 return "Hai"+s; 
    	} 
    }
    client code caling
    public class RmServiceClient {
    	public static void main(String args[]) 
    	   { 
    	  try 
    	  { 
    	   System.out.println("Wait.."); 
    	   String s1="Jihad........";
    	   Resource  res = new ClassPathResource("rmservice.xml"); 
    	   BeanFactory  factory = new  XmlBeanFactory(res); 
    	   System.out.println("factory created"); 
    	   RmService bean1 = (RmService)factory.getBean("rmservice"); 
    	   String s = bean1.getResult(s1); 
    	   System.out.println(s); 
    	  } 
    	  catch(Exception e1) 
    	   {System.out.println(""+e1);} 
    	   } 
    }
    and Xml files.
    <bean id="rmserver" 
      class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> 
       <property name="serviceUrl"> 
       <value>rmi://10.105.188.37:1099/rmserver</value>   
       </property> 
       <property name="serviceInterface"> 
       <value>com.vijay.RmServer</value> 
       </property> 
      </bean> 
      <bean   id="rmserverimpl"  class="com.vijay.RmServerImpl"> 
       <property name="rmServer" ref="rmserver"></property>
      </bean>
    </beans>
    
    <bean  class="org.springframework.remoting.rmi.RmiServiceExporter"> 
       <property name="service"> 
       <value>rmservice</value>   
       </property> 
       <property name="serviceName"> 
       <value>service1</value>   
       </property> 
       <property name="serviceInterface"> 
       <value>rmservice</value> 
       </property> 
       </bean> 
       <bean id="rmservice" class="com.vijay.RmServiceImpl"> 
       </bean> 
    </beans>
    can some one guide me to write me first Spring Rmi program and how ro rectify the error.

    Thank you in advacne.

  • #2
    I suggest a read of the reference guide the part about RMI...

    1) Create a simple POJO don't extend UnicastRemoteObject and Remote interface (spring handles all that for you)
    2) Don't use a BeanFactory use an ApplicationContext (again read the reference guide to get to know the differences between the 2).
    3) Your serviceInterface is wrong it should be an actual interface not some name
    4) your service should be the REFERENCE (not VALUE) to the service you want to expose.
    5) Your client does nothing with the exposed service so not sure what you want to accomplish.

    Comment


    • #3
      Thank you for your corrections. this time i have followed the documentation. i am sucessfully getting the result(In list mehtod i added on name and getting that name in SimpleObject class). I think this value is coming from RMI registry.

      even i am not sure what i am going to work on. This is my first sample on RMi. could please tell me the scenarios where all i can use this.

      Thank you for your valuble time.

      Vijay

      Comment

      Working...
      X