jse应用服务器,在JDK6 HTTP服务器上使用Spring 3的REST服务

Spring MVC的要求Servlet API的

您可以创建一个简单的REST服务使用JSE 6 HTTP服务器以下way

您创建资源类

@Path("/helloworld")

public class MyResource {

// The Java method will process HTTP GET requests

@GET

// The Java method will produce content identified by the MIME Media

// type "text/plain"

@Produces("text/plain")

public String getClichedMessage() {

// Return some cliched textual content

return "Hello World";

}

}

您创建一个REST应用

public class MyApplication extends javax.ws.rs.core.Application{

public Set> getClasses() {

Set> s = new HashSet>();

s.add(MyResource.class);

return s;

}

}

这就是如何开始你的服务器

HttpServer server = HttpServer.create(new InetSocketAddress(8080), 25);

HttpContext context = server.createContext("/resources");

HttpHandler handler = RuntimeDelegate.getInstance().createEndpoint

(new MyApplication(), HttpHandler.class);

context.setHandler(handler);

server.start();

这就是全部。不需要Spring MVC。

为了测试的目的,这个工作得很好,对于有很多请求的高效用法,我会使用像Jetty或Tomcat这样的WebContainer。

的如何使用标准JSE 6的HttpServer打造一个宁静的更详细的描述,可以发现 RESTFul Webservice mit JAX-RS(德国)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值