我从jersey2开始了一个简单的项目,但是当我完成配置后,我发现在url中搜索我的资源404时找不到。
我正在使用gradle,所以我的依赖项看起来像:
//https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api
compileOnly group: 'javax.servlet', name: 'javax.servlet-api', version: '3.0.1'
/* HATEOAS */
// https://mvnrepository.com/artifact/org.glassfish.jersey.ext/jersey-declarative-linking
compile group: 'org.glassfish.jersey.ext', name: 'jersey-declarative-linking', version: '2.27'
// https://mvnrepository.com/artifact/org.glassfish.jersey.core/jersey-server
compile group: 'org.glassfish.jersey.core', name: 'jersey-server', version: '2.27'
//Jackson
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.9.6'
// https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api
compile group: 'javax.ws.rs', name: 'javax.ws.rs-api', version: '2.1'
// https://mvnrepository.com/artifact/org.glassfish.jersey.bundles/jaxrs-ri
compile group: 'org.glassfish.jersey.bundles', name: 'jaxrs-ri', version: '2.27'
可能我有更多需要的依赖项,但是我测试了很多组合,但没有任何结果...
我的课程配置也是如此:
package com.apporelbotna.appuestas.rest.initialization;
import javax.servlet.ServletContext;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Provider;
import org.glassfish.jersey.server.ResourceConfig;
@Provider
@javax.ws.rs.ApplicationPath("/webservice")
public class RestResourceConfig extends ResourceConfig
{
@Context
public void setServletContext(ServletContext context)
{
if (context != null)
{
context.getInitParameter("system.info.allow");
}
}
public RestResourceConfig()
{
// Register components in a package
packages("com.apporelbotna.appuestas.rest.resource");
}
}
我的资源是:
package com.apporelbotna.appuestas.rest.resource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("/contest")
public class ContestResource
{
@GET
@Produces(MediaType.TEXT_PLAIN)
public String get()
{
return "3";
}
}
我正在使用Eclipse IDE在Tomcat 9中工作。我也跳过了web.xml,因为我读到注释类扩展ResourceConfig并没有必要
我正在跳过什么?
干杯,您太棒了!