运行项目
install:安装,你会看到制品放入本地仓库 -Pserver: 运行服务器,程序会自动启动 jetty -Pclient: 运行客户端程序pom.xml 右键 - Run As - 2 Maven build 输入install: 控制台部分输出: 运行-Pserver(方法同上) 控制台部分输出: 在浏览器中输入URL http://localhost:9000/customerservice/customers/123 得到如下结果: 对于这个返回结果README.txt中有如下说明:
@GET //#@GET HTTP协议方法,常见的有 GET,PUT,POST,DELETE 等 @Path("/customers/{id}/") //#@Path(“/customers/{id}/”) 项目根访问该方法的 URI 路径,其中 {ID} 是一个变量模板, @PathParam(“id”) 可以获取该变量。 public Customer getCustomer(@PathParam("id") String id) { System.out.println("----invoking getCustomer, Customer id is: " + id); long idNumber = Long.parseLong(id); Customer c = customers.get(idNumber); return c; }实验:修改@Path 为 @Path(“/myservice/”),用 curl -v 给出结果 打开customerServer.java: 修改为 重新执行maven命令install和-Pserver -Pserver时会报错: 是因为9000端口被占用。退出ecplipse再重新打开执行-Pserver 。 启动成功: 访问http://localhost:9000/myservice/customers/123 可以正常访问得到如下结果: 用curl -v指令: