maven + hessian 简单例子
来源:互联网 发布:网络黑侠现在在哪写书 编辑:程序博客网 时间:2024/05/21 14:07
项目结构如下:
pom.xml 内容:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.lala</groupId><artifactId>hessian-web</artifactId><packaging>war</packaging><version>1.0.0</version><name>hessian-web Maven Webapp</name><url>http://maven.apache.org</url><dependencies><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.10</version><scope>test</scope></dependency><dependency><groupId>javax.servlet</groupId><artifactId>jsp-api</artifactId><version>2.0</version><scope>provided</scope></dependency><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>3.0.1</version><scope>provided</scope></dependency><dependency><groupId>com.caucho</groupId><artifactId>hessian</artifactId><version>4.0.38</version></dependency></dependencies><build><finalName>hessian-web</finalName><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>3.3</version><configuration><source>1.8</source><target>1.8</target><verbose>true</verbose></configuration></plugin><plugin><groupId>org.eclipse.jetty</groupId><artifactId>jetty-maven-plugin</artifactId><version>9.2.11.v20150529</version><configuration><stopKey>foo</stopKey><stopPort>9999</stopPort><httpConnector><port>3389</port></httpConnector><webApp><contextPath>/</contextPath></webApp></configuration></plugin></plugins></build></project>
package com.lala.service;import java.util.Map;public interface UserService {public Map<String, Object> getById(long id);public String get();}
package com.lala.service;import java.util.HashMap;import java.util.Map;public class UserServiceImpl implements UserService{public String get(){return "get method invoke";}public Map<String, Object> getById(long id) {if(id <= 0){return null;}Map<String, Object> result = new HashMap<>();result.put("id", id);result.put("name", "英布");result.put("position", "九江王");return result;}}
servlet如下:
package com.lala.servlet;import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.annotation.WebInitParam;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.caucho.hessian.server.HessianServlet;@WebServlet(value = "/hessian/user", initParams={@WebInitParam(name="service-class",value="com.lala.service.UserServiceImpl")})public class UserHessianServlet extends HessianServlet{private static final long serialVersionUID = 1L;public void init() throws ServletException {super.init();}protected void service(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException{super.service(req, resp);}}
然后,启动jetty服务
mvn jetty:run
调用代码
package com.client;import com.caucho.hessian.client.HessianProxyFactory;import com.lala.service.UserService;public class App {public static void main(String[] args)throws Exception{HessianProxyFactory factory = new HessianProxyFactory(); String url = "http://127.0.0.1:3389/hessian/user";UserService us = (UserService)factory.create(UserService.class,url); System.out.println(us.getById(2l));System.out.println(us.get());}}
7 0
- maven + hessian 简单例子
- HESSIAN 简单例子
- Hessian---简单例子
- hessian简单小例子
- hessian简单原理及实现例子--学习
- Hessian Spring相关使用的简单例子
- hessian 例子
- MAVEN的一个简单例子
- disconf简单例子(maven)
- Maven下SpringMVC简单例子
- hessian简单实例
- 简单Hessian实例
- Hessian简单入门
- Hessian简单入门
- hessian简单实例
- 简单的Hessian实例
- Hessian简单示例
- hessian 的简单介绍
- 哈希(3) - 判断一个数组是否为另一个数组的子集
- Android IntentService解析
- angular directive实例第一发 jquery插件datepicker转化成指令
- 将一张JPEG图片通过嵌入式linux的帧缓冲机制绘制到7寸触摸屏上
- Hadoop开发环境
- maven + hessian 简单例子
- UITableView优化技巧
- 解决MySql 数据库 提示:1045 access denied for user 'root'@'localhost' using password yes
- Subsets - LeetCode 78
- BZOJ 2648/2716(SJY摆棋子-KD_Tree)[Template:KD_Tree]
- enable usb tethering via command line failed
- 【LDA】修正 GibbsLDA++-0.2 中的两个内存问题
- Linux常用命令-文件搜索命令-文件搜索命令find
- GPIO