Hi all,
I'm trying to get a simple Spring application to work in a Server/Client mode. I'm using Tomcat 5.5.23, Spring 2.0.5.
For the Server I have the following code:
HelloWorld.java
Code:package com.all4me.rmiservertest; import java.rmi.*; public interface HelloWorld extends Remote { public String getHelloWorld() throws RemoteException; }
HelloWorldImpl.java
applicationContext.xmlCode:package com.all4me.rmiservertest; import java.io.Serializable; public class HelloWorldImpl implements HelloWorld, Serializable { static final long serialVersionUID = 1L; /** Creates a new instance of HelloWorld */ public HelloWorldImpl() { } public String getHelloWorld() { return "Yes it's the venerable Hello World again."; } }
Code:<?xml version="1.0"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="helloWorldService" class="com.all4me.rmiservertest.HelloWorldImpl"> </bean> <bean id="helloWorldServiceExporter" class="org.springframework.remoting.rmi.RmiServiceExporter"> <property name="serviceName" value="HelloWorld"/> <property name="service" ref="helloWorldService"/> <property name="serviceInterface" value="com.all4me.rmiservertest.HelloWorld"/> <property name="registryPort" value="9000"/> <property name="servicePort" value="9001"/> </bean> </beans>
web.xml
For the Client I have the following Code:Code:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file> index.jsp </welcome-file> </welcome-file-list> </web-app>
HelloWorldHandler.java
applicationContext.xmlCode:package com.all4me.rmiclienttest; import com.all4me.rmiservertest.HelloWorld; public class HelloWorldHandler { private static HelloWorld helloWorld; public void setHelloWorld(HelloWorld helloWorld) { this.helloWorld = helloWorld; } public HelloWorld getHelloWorld() { return helloWorld; } /** Creates a new instance of HelloWorldHandler */ public HelloWorldHandler() { } public String getHelloWorldString() { return helloWorld.getHelloWorld(); } }
web.xmlCode:<?xml version="1.0"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="helloWorldService" class="org.springframework.remoting.rmi.RmiProxyFactoryBean"> <property name="serviceUrl" value="rmi://localhost:9000/HelloWorld"/> <property name="serviceInterface" value="com.all4me.rmiservertest.HelloWorld"/> </bean> <bean id="helloWorldHandler" class="com.all4me.rmiclienttest.HelloWorldHandler"> <property name="helloWorldService" ref="helloWorldService"/> </bean> </beans>
Code:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <session-config> <session-timeout> 30 </session-timeout> </session-config> <welcome-file-list> <welcome-file> index.jsp </welcome-file> </welcome-file-list> </web-app>


Reply With Quote