最近研究rest接口,发现restlet应用挺广泛,不过入门资料很少,去官网下载jar包,根据官网说明搭建了一个简单的restlet工程:
1、首先导入jar包
- org.restlet.jar
- org.restlet.ext.servlet.jar
2、编写业务逻辑类
package com.chen.rest;import org.restlet.resource.Get;import org.restlet.resource.ServerResource;/** * @author chenjie * @version 1.0 * @since 2017-02-08 */public class HelloWorld extends ServerResource{ @Get public String represent() { return "hello world!"; }}
3、编写应用类
package com.chen.rest;import org.restlet.Application;import org.restlet.Restlet;import org.restlet.routing.Router;/** * @author chenjie * @version 1.0 * @since 2017-02-08 */public class FirstApp extends Application{ @Override public synchronized Restlet createInboundRoot() { System.out.println("1111111111"); Router router = new Router(getContext()); router.attach("/hello",HelloWorld.class); return router; }}
4、配置web.xml
first steps servlet RestletServlet org.restlet.ext.servlet.ServerServlet org.restlet.application com.chen.rest.FirstApp RestletServlet /*
5、部署工程到tomcat,启动tomcat,访问