我的第一个Hessian服务

开了账号这么多年了,今天第一次来这写东西。我今天要说说的写的第一个hessian服务。

 

这次我用的是spring+hessian来做的web服务。

 

首先建立这样一个服务要引入srping的一些包,主要有core,web,remoting还有一个重要的包叫aop。

就是因为没有这个包让的原本写好的程序莫名其妙的报错,找了半天才找到的。

 

首先发布服务我们要对外做一个接口:下面是代码

public interface IHelloHessian {
	public String SayHello();
}

有了接口你总得通过接口做一些事吧,下面我们来做事

public interface IHelloHessian {
	public String SayHello();
}

 

事是做完了。可是外部还是不能调用啊,spring要做的大量的工作就是配置,接下来我们来置applicationContext.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-3.0.xsd">
	<bean id="helloHessian" class="com.kane.HelloHessian">
	</bean>

</beans>

 

这完了以后,你要向外中指定用那个吧,那就再来一个对外用的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"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
	<!-- 业务类 -->  
	<bean id="hessianService" class="com.kane.HelloHessian"/>  
	           
	<!-- 远程服务 -->  
	<bean name="/helloHessian" class="org.springframework.remoting.caucho.HessianServiceExporter">  
	    <property name="service" ref="helloHessian"/>  
	    <property name="serviceInterface">  
	        <value>  
	            com.kane.IHelloHessian  
	        </value>  
	    </property>  
	</bean> 
</beans> 

 这好了,spring + hessian是通过servlet拦截实现的,那现在我们就要配web.xml文件了。

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
	xmlns="http://java.sun.com/xml/ns/javaee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
	http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
	<context-param>
		<param-name>contextConfigLocation</param-name> 
		<param-value>
			/WEB-INF/config/applicationContext.xml
		</param-value>   
	</context-param>
	<listener>
       <listener-class>
           org.springframework.web.context.ContextLoaderListener
       </listener-class>
    </listener>
	<servlet>
		<servlet-name>Hessian</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>1</load-on-startup> 
	</servlet>
	<servlet-mapping>
		<servlet-name>Hessian</servlet-name>
		<url-pattern>/hessian/*</url-pattern>
	</servlet-mapping>  
</web-app>

 

到现在为止你可以项目放到你的服务器上进行发布了。

 

我的文章到也就写完了。希望大家不要走弯路了。

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值