RESTEasy – javax.ws.rs.NotFoundException:无法找到完整路径的资源
我试图在GWT项目中使用RESTEasy实现REST服务,但是当我进入相应的URI时,应用程序返回:
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)
我的web.xml是:
resteasy.servlet.mapping.prefix /api Resteasy org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher javax.ws.rs.Application eii.api.MatchApplication Resteasy /api/*
应用程序的实现:
public class MatchApplication extends Application { private Set singletons = new HashSet(); private Set<Class> classes = new HashSet<Class>(); public MatchApplication() { singletons.add(new MatchServiceImpl()); } @Override public Set<Class> getClasses() { return classes; } @Override public Set getSingletons() { return singletons; } }
这是提供REST服务的类:
/* 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(); } ... }
我想要的是在进入时返回一个JSON文件,例如: http://127.0.0.1:8888/api/matches
: http://127.0.0.1:8888/api/matches
: 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
是随机字符串),浏览器会显示Error 404
。
此外,我尝试了RESTClient插件,这些是返回的答案:
使用http://127.0.0.1:8888/api/
或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
并与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
注意Content-Type: text/html; charset=iso-8859-1
Content-Type: text/html; charset=iso-8859-1
不在第一个。
您使用名为getMatches()
的方法添加了资源,Resteasy对此一无所知。 您需要覆盖Application
的getSingletons()
方法并从那里返回您的根资源,如下所示。
文档在这里
例:
public class MatchApplication extends Application { private Set
首先,我认为您的MatchApplication类应该使用@ApplicationPath(“/ api”)进行注释。 如果已经完成,我很抱歉。
然后,根据您的RESTEasy版本,它将自动扫描作为提供者或资源的类,因此您暂时不需要在MatchApplication上实现任何内容。 只需扩展应用程序即可完成。
如果您可以更新您的Web应用程序以使用servlet 3.0,则无需在Web.xml中添加任何类型的配置。
阅读有关RESTEasy文档的更多信息 。
这适用于我的所有服务。
This is a runtime exception indicating a resource requested by a client was not found on the server. Add below entry into your web.xml : resteasy.resources com.org.abc.xyz.MainClassName