在 JBoss 社区 AS 7 中部署简单的 Jax-RS 示例
我正在尝试在 JBOSS AS 7 中部署一个简单的 REST 示例,但似乎我做错了什么,而且我现在一无所知。我正在使用 Eclipse 插件进行部署。
我编写的类如下
@Path("/resources")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public class ReceivedImagePersister {
@POST
@Path("/image")
public Response save(String entry) {
return Response.ok().build();
}
}
然后我创建一个 web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>API</display-name>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
</web-app>
和一个 jboss-web.xml
<jboss-web>
<context-root>api</context-root>
</jboss-web>
当我部署应用程序并尝试将一些数据发送到 RESTful servlet 时,响应始终是:(
无法找到相对资源:/完整路径的图像: http://localhost:8080/api/resources/image)
我可以吗必须对配置进行一些更改?
预先非常感谢。
I'm trying to deploy a simple REST example in JBOSS AS 7 but seems that I'm doing something wrong and I'm now clueless. I'm using Eclipse plugin to deploy.
The class I wrote is the following
@Path("/resources")
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
public class ReceivedImagePersister {
@POST
@Path("/image")
public Response save(String entry) {
return Response.ok().build();
}
}
Then I create a web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>API</display-name>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
</web-app>
And a jboss-web.xml
<jboss-web>
<context-root>api</context-root>
</jboss-web>
When I deploy the application and try to send some data to the RESTful servlet the response is always:
(Could not find resource for relative : /image of full path: http://localhost:8080/api/resources/image)
Do I have to make some changes in configuration?
Thanks a lot in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你的 web.xml 你的 url 模式应该 /* 即
应该是
我得到的是你需要让 javax.ws.rs.core.Application 从 http://localhost/api/ 只有这样它才能检测到有一个名为“resources”的资源,它有方法“image”
现在它正在尝试查找上下文路径下名为“image”的资源/api/resources/
以下网址可能适用于现在的设置方式
http://localhost:8080/api/resources/resources/image
I think your web.xml your url pattern should /* i.e.
should be
What i am getting at is you need let javax.ws.rs.core.Application parse your url starting from http://localhost/api/ only then will it able to detect that there is a resource named "resources" which has method "image"
Right now it is trying to lookup a resource named "image" which is under the context path /api/resources/
The following url may work for the way its been setup now
http://localhost:8080/api/resources/resources/image
我没有任何使用 JBoss 的经验,但如果您希望与 Java EE 6 部署模型实现最佳兼容性,您可能应该使用 Servlet 3.0 web.xml 而不是 2.4。
I don't have any experience with JBoss but you should probably use a Servlet 3.0 web.xml instead of a 2.4 if you want the best compatibility with the Java EE 6 deployment model.
访问您声明的内容的正确 url 是:
第一个资源是 servlet 映射,第二个是其余控制器的名称。
The correct url for accessing what you have declared is:
The first resources is the servlet mapping, and the second is the name of the rest controller.