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(德国)