When to use javax.ws.rs.core.Application to create

2019-04-07 04:30发布

I have developed RESTful web services in two ways:

  1. used a class that extends javax.ws.rs.core.Application without defining a web.xml file, using Glassfish.

  2. haven't used javax.ws.rs.core.Application but included a web.xml and a Jersey implementation, using Tomcat.

Is there a preferred way of building RESTful web services with JAX-RS?

1条回答
仙女界的扛把子
2楼-- · 2019-04-07 05:12

Using the javax.ws.rs.core.Application class is the preferred way and also the only portable way of configuring resources and providers in a JAX-RS web service, so if possible that would be the recommended way to set it up.

But that works well only in JAX-RS aware servlet containers or application servers, for JAX-RS non aware servers you need other ways for deployment and that most of the times means some proprietary servlet class of the JAX-RS implementation you are using.

To get more details on the subject, see for example the Jersey documentation, Deploying a RESTful Web Service (for Jersey v1.x) and Application Deployment and Runtime Environments (for Jersey v2.x).

查看更多
登录 后发表回答