Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 872
idbentley Avatar asked Dec 29 '11 00:12

idbentley


1 Answers

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).

like image 152
Pavel Bucek Avatar answered Sep 27 '22 18:09

Pavel Bucek