我是Spring和Hessian的新手,之前從未使用過。寫作hessian serivce
我想寫一個小小的Hello World程序,清楚地顯示這個服務是如何工作的。
我使用Maven列出項目詳細信息和依賴關係。
網上提供的黑森森資源並不完整,是一步一步的指導。如果我得到幫助的形式別人誰曾寫麻袋服務
謝謝
我是Spring和Hessian的新手,之前從未使用過。寫作hessian serivce
我想寫一個小小的Hello World程序,清楚地顯示這個服務是如何工作的。
我使用Maven列出項目詳細信息和依賴關係。
網上提供的黑森森資源並不完整,是一步一步的指導。如果我得到幫助的形式別人誰曾寫麻袋服務
謝謝
用於實現黑森州可調用服務的步驟
將不勝感激是:
讓我們通過一個例子。創建一個Java接口:
public interface EchoService {
String echoString(String value);
}
寫的Java類實現此接口:
public class EchoServiceImpl implements EchoService {
public String echoString(String value) {
return value;
}
}
在web.xml
文件,配置一個servlet:
<servlet>
<servlet-name>/EchoService</servlet-name>
<servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>/EchoService</servlet-name>
<url-pattern>/remoting/EchoService</url-pattern>
</servlet-mapping>
配置服務類的一個實例在Spring應用程序上下文中:
<bean id="echoService" class="com.example.echo.EchoServiceImpl"/>
在Spring應用程序上下文中配置導出器。 bean名稱必須與servlet名稱匹配。
<bean
name="/EchoService"
class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="echoService"/>
<property name="serviceInterface" value="com.example.echo.EchoService"/>
</bean>
客戶端必須創建遠程接口的代理。你可以簡單地寫一個JUnit測試:
HessianProxyFactory proxyFactory = new HessianProxyFactory();
proxyFactory.setHessian2Reply(false);
proxyFactory.setHessian2Request(false);
com.example.echo.EchoService service = proxyFactory.create(
com.example.echo.EchoService, "http://localhost:8080/<optional-context/>remoting/EchoService");
Assert.equals(service.echoString("test"), "test");
謝謝,我該如何測試它? – daydreamer 2011-01-25 01:21:20
請參閱我的答案請爲測試案例。 – Konsumierer 2012-11-22 16:15:20