问题描述
我试图在GWT项目中使用RESTEasy实现REST服务,但是当我进入相应的URI时,应用程序将返回:
Grave:未能执行
javax.ws.rs.NotFoundException:无法找到完整路径的资源:http://127.0.0.1:8888/api/matches
org。 jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73)
at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48)
at org。 jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444)
at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234)
at org.jboss.resteasy。 core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:171)
org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
at org.jboss.resteasy。 plugins.server.servlet.HttpServletDispatcher.service(HttpServletD在HttpServlet.service(HttpServlet.java:56)
在org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
在javax.servlet.http.HttpServlet.service java:717)
我的web.xml是:
<?xml version =1.0encoding =UTF-8standalone =no?>< web-app xmlns =http:// java .sun.com / xml / ns / javaeexmlns:xsi =http://www.w3.org/2001/XMLSchema-instanceversion =2.5xsi:schemaLocation =http://java.sun。 com / xml / ns / javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd\">
< context-param>
< param-name> resteasy.servlet.mapping.prefix< / param-name>
< param-value> / api< /参数值>
< / context-param>
<! - Servlets - >
< servlet>
< servlet-name> Resteasy< / servlet-name>
< servlet-class> org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher< / servlet-class>
< init-param>
< param-name> javax.ws.rs.Application< / param-name>
< param-value> eii.api.MatchApplication< / param-value>
< / init-param>
< / servlet>
<! - Servlet映射 - >
< servlet-mapping>
< servlet-name> Resteasy< / servlet-name>
< url-pattern> / api / *< / url-pattern>
< / servlet-mapping>
< / web-app>
执行申请:
public class MatchApplication extends Application {
private Set< Object> singletons = new HashSet< Object>();
private Set< Class<?>> classes = new HashSet< Class<>>();
public MatchApplication(){
singletons.add(new MatchServiceImpl());
}
@Override
public Set< Class<>> getClasses(){
返回类;
}
@Override
public Set< Object> getSingletons(){
返回单身人士;
$ / code>
以下是提供REST服务的类:
/ *汇入* /
...
@Path(/ matches)
public class MatchResource {
private static MatchResource _instance = null;
专用MatchRepository存储库;
public MatchResource(){
repository = new MapMatchRepository();
$ b $ public static MatchResource getInstance(){
if(_instance == null)
_instance = new MatchResource();
return _instance;
$ b @GET
@Path(/ {id})
@Produces(application / json)
public Match getMatch( @PathParam(id)int id){
return repository.getMatch(id);
}
@GET
@Produces(application / json)
公共匹配getMatchesCurrentRound(){
return repository.getMatchesCurrentRound();
}
...
}
我想要的是在进入时返回一个JSON文件,例如: http://127.0.0.1:8888/api/matches
有人知道我在做什么错吗?
编辑:
如果我访问 http://127.0.0.1:8888/api/ 或 http://127.0.0.1: 8888 / api / * (其中*是您想要编写的任何内容),浏览器不显示任何内容。但是,如果我访问 http://127.0.0.1:8888/oqiwn (其中 oqiwn 是随机字符串)浏览器显示错误404 。
另外,我尝试了RESTClient插件,它们是返回的答案:使用 http://127.0.0.1:8888/api/ 或 http ://127.0.0.1:8888 / api / *
状态码:404未找到
Cache-Control:no-cache
内容长度:0
日期:2013年11月10日星期日22:59:57 GMT
过期时间:1990年1月1日星期五00:00 :00 GMT
服务器:开发/ 1.0
http ://127.0.0.1:8888 / oqiwn
状态码:404未找到
Cache-Control:no-cache
Content-Length:83
Content-Type:text / html; charset = iso-8859-1
日期:2013年11月10日星期日22:59:05 GMT
过期时间:1990年1月1日星期五00:00:00 GMT
服务器:Development / 1.0
请注意 Content-Type:text / html;
您添加了资源使用名为 getMatches()的方法,Resteasy对此一无所知。您需要重写 Application 的 getSingletons()方法,并从那里返回您的根资源,如下所示。 p>
public class MatchApplication extends Application {
private Set< Object> singletons = new HashSet< Object>();
private Set< Class<?>> classes = new HashSet< Class<>>();
public MatchApplication(){
singletons.add(new MatchServiceImpl());
}
@Override
public Set< Class<>> getClasses(){
返回类;
}
@Override
public Set< Object> getSingletons(){
返回单身人士;
}
}
I've tried to implement a REST service with RESTEasy in a GWT project, but when I get into the respective URI the application returns:
Grave: failed to execute javax.ws.rs.NotFoundException: Could not find resource for full path: http://127.0.0.1:8888/api/matches at org.jboss.resteasy.core.registry.ClassNode.match(ClassNode.java:73) at org.jboss.resteasy.core.registry.RootClassNode.match(RootClassNode.java:48) at org.jboss.resteasy.core.ResourceMethodRegistry.getResourceInvoker(ResourceMethodRegistry.java:444) at org.jboss.resteasy.core.SynchronousDispatcher.getInvoker(SynchronousDispatcher.java:234) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:171) at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56) at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51) at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
My web.xml is:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- All REST resources will be prefixed by /api --> <context-param> <param-name>resteasy.servlet.mapping.prefix</param-name> <param-value>/api</param-value> </context-param> <!-- Servlets --> <servlet> <servlet-name>Resteasy</servlet-name> <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class> <init-param> <param-name>javax.ws.rs.Application</param-name> <param-value>eii.api.MatchApplication</param-value> </init-param> </servlet> <!-- Servlet mappings --> <!-- All calls to /api/xxx will be sent to the reasy servlet --> <servlet-mapping> <servlet-name>Resteasy</servlet-name> <url-pattern>/api/*</url-pattern> </servlet-mapping> </web-app>
The implementation of Application:
public class MatchApplication extends Application { private Set<Object> singletons = new HashSet<Object>(); private Set<Class<?>> classes = new HashSet<Class<?>>(); public MatchApplication() { singletons.add(new MatchServiceImpl()); } @Override public Set<Class<?>> getClasses() { return classes; } @Override public Set<Object> getSingletons() { return singletons; } }
And here's the class that provide the REST service:
/* Imports */ ... @Path("/matches") public class MatchResource { private static MatchResource _instance = null; private MatchRepository repository; public MatchResource() { repository = new MapMatchRepository(); } public static MatchResource getInstance() { if (_instance == null) _instance = new MatchResource(); return _instance; } @GET @Path("/{id}") @Produces("application/json") public Match getMatch(@PathParam("id") int id) { return repository.getMatch(id); } @GET @Produces("application/json") public Matches getMatchesCurrentRound() { return repository.getMatchesCurrentRound(); } ... }
What I want is to return a JSON file when getting into, for example: http://127.0.0.1:8888/api/matches
Does anyone know what I'm doing wrong?
Edit:
If I access to http://127.0.0.1:8888/api/ or http://127.0.0.1:8888/api/* (where * is whatever you want to write), the browser shows nothing. However, if I access to http://127.0.0.1:8888/oqiwn (where oqiwn is a random string) the browser shows a Error 404.
Also, I tried the RESTClient addon and these are the answers that returns:
With http://127.0.0.1:8888/api/ or http://127.0.0.1:8888/api/*
Status Code: 404 Not Found Cache-Control: no-cache Content-Length: 0 Date: Sun, 10 Nov 2013 22:59:57 GMT Expires: Fri, 01 Jan 1990 00:00:00 GMT Server: Development/1.0
And with http://127.0.0.1:8888/oqiwn
Status Code: 404 Not Found Cache-Control: no-cache Content-Length: 83 Content-Type: text/html; charset=iso-8859-1 Date: Sun, 10 Nov 2013 22:59:05 GMT Expires: Fri, 01 Jan 1990 00:00:00 GMT Server: Development/1.0
Note that Content-Type: text/html; charset=iso-8859-1 is not in the first one.
You added your resource using a method named getMatches(), which Resteasy knows nothing about. You need to override the getSingletons() method of Application and return your root resources from there as shown below.
Example:
public class MatchApplication extends Application { private Set<Object> singletons = new HashSet<Object>(); private Set<Class<?>> classes = new HashSet<Class<?>>(); public MatchApplication() { singletons.add(new MatchServiceImpl()); } @Override public Set<Class<?>> getClasses() { return classes; } @Override public Set<Object> getSingletons() { return singletons; } }
这篇关于RESTEasy - javax.ws.rs.NotFoundException:无法找到完整路径的资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!