我想让我的第一个泽西Web服务项目工作,但我得到这个错误Jersey: The requested resource is not available.
我已经安装Jersey 2.16
eclispe Maven和安装Tomcat 8.0.21
我已经craeted MessageResource.java类里面scr/main/java - org.test.messanger
泽西:请求资源不可用
我打字此链接:
http://localhost:8080/messanger/webapi/messages
如果我克利克此链接http://localhost:8080/messanger/webapi/myresource
我得到Got it!
我加入Jersy与行家与此数据:
- org.glassfish.jersey.archetypes
- Jersey的快速启动-web应用
- 2.16
MessageResource.java
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/messages")
public class MessageResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getMessages(){
return "Hello world";
}
}
作业编号:
package org.test.messanger;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
/**
* Root resource (exposed at "myresource" path)
*/
@Path("myresource")
public class MyResource {
/**
* Method handling HTTP GET requests. The returned object will be sent
* to the client as "text/plain" media type.
*
* @return String that will be returned as a text/plain response.
*/
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getIt() {
return "Got it!";
}
}
的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>org.test.messanger</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/webapi/*</url-pattern>
</servlet-mapping>
</web-app>
请停止删除您的帖子,并再次发布**完全相同的问题。这已经是第三次了。 –
你给我们展示的东西看起来很好。问题在于你没有向我们展示或告诉我们的东西。只是为了让您知道您可能没有得到答案的原因,是因为问题不能从您提供的内容中重现或发现。这并不是说你没有提供一个很好的示例/好问的问题,它只是提供了一个可靠的工作示例。我一直在使用这个原型,并且从来没有遇到过你正在面临的问题 –
我只是说运行一个'mvn clean package'。从'target'中取出'.war'并将其放入Tomcat'webapp'中。删除任何旧战争(爆炸战争)。启动Tomcat。然后在webapps里面看看爆炸的战争,确保这个类在WEB-INF/classes –