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.
Here is my code what i have written.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
can some one guide me to write me first Spring Rmi program and how ro rectify the error.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>
Thank you in advacne.


Reply With Quote