JAX-RS 和 Jersey - 多个公开的资源中只有一个
我已经开始使用 JAX-RS 和 Jersey 来启动 RESTful Web 服务,该服务公开两个资源:SessionResource 和 ItemResource。遗憾的是,Web 服务仅公开其中之一。
详细信息:
- 配置是通过扩展 javax.ws.rs.core.Application 的类(由 Netbeans 7 自动创建)完成的。该类不包含除 @ApplicationPath() 注释之外的任何配置信息。
- 没有 web.xml 文件
问题:
- 我缺少什么?
- 拥有应用程序类是否有价值?我可以只使用 web.xml 文件进行配置吗?
- 有时我注意到 IDE 中所做的更改不会发布到 apache。最可靠的方法是什么?
I've got the start of a RESTful web service using JAX-RS and Jersey that exposes two resources: SessionResource and ItemResource. Only one of these, unfortunately, is exposed by the web service.
Details:
- configuration is done w/ a class that extends javax.ws.rs.core.Application (created automatically by Netbeans 7). the class doesn't contain any configuration information other than a @ApplicationPath() annotation.
- no web.xml file
Questions:
- What am I missing?
- is there value to having an application class? can i get away w/ just a web.xml file for configuration?
- sometimes i've noticed that changes made in the IDE aren't published to apache. what is the most reliable way to do so?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
多种解决方案之一是重写 JAX-RS 应用程序的
getClasses()
。据我所知,最好不要依赖资源和提供者的自动检测。有时,如果您有多个 JAX-RS 应用程序,它可能会产生副作用。
One of multiple solutions is to override
getClasses()
of your JAX-RS application.As I learned it is better not to rely on the automatic detection of resources and providers. Sometimes it can have sideeffects if you have more than one JAX-RS application.
您可以在 web.xml 中执行此操作,然后您就不需要 Application 类。
然后它会自动检测
com.yourCompany
及其子包中所有用@Path
注解的类,并将它们视为资源。You can do this in your web.xml and then you shouldn't need the Application class.
Then it will automatically detect all classes in
com.yourCompany
and its subpackages, which are annotated with@Path
, and treat them as resources.