Jersey No WebApplication provider is present when jersey-* dependency added

萝らか妹 提交于 2019-12-19 13:38:11

问题


I have a simple Spring & Jersey application, which works perfectly well for consuming requests through a simple Resource. However, I'd like to return a JSON response - containing a simple JSON serialization of an object. To achieve this, I've added a maven dependency for jersey-json. As soon as I add this dependency, however, I get this error at server startup:

com.sun.jersey.api.container.ContainerException: No WebApplication provider is present  at      
     com.sun.jersey.spi.container.WebApplicationFactory.createWebApplication(WebApplicationFactory.java:69) at
     com.sun.jersey.spi.container.servlet.ServletContainer.create(ServletContainer.java:391)

I'm not totally clear upon exactly what a provider is, but I'm pretty certain that there should be a default one found.

For completeness, here's my Resource:

@Path("/scan")
@Resource
@Component
public class ScanResource {
    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/{barcode}")
    public List<Scan> getScansForBarcode(@PathParam("barcode") Long barcode){
        ..snip..
        return results;
    }
}

A Scan object is a simple Entity Bean object.

The mvn dependency is:

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>1.11</version>
</dependency>

Does anyone know why I might be getting the No WebApplication provider is present Exception? Any thoughts on how I might resolve it?

Thanks


回答1:


You need to have jersey-server jar on your classpath as well. And you need to make sure that all your jars are from the same version, Jersey runtime won't be able to use provided classes otherwise.

Additionally (most likely not relevant here, but..) there is a recent change in module structure - servlet dependencies were separated to new modules. So if you are using servlets, you might want to depend on jersey-servlet (which depends on jersey-server).




回答2:


I am also had this issue. The issue was resolved by having same version for "jersey-json" and "jersey-servlet"maven dependencies.

EX:

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-json</artifactId>
    <version>1.13</version>
</dependency>
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-servlet</artifactId>
    <version>1.13</version>
</dependency>


来源:https://stackoverflow.com/questions/8662919/jersey-no-webapplication-provider-is-present-when-jersey-dependency-added

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!