idbentley
idbentley

Reputation: 4218

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

Upvotes: 12

Views: 21855

Answers (2)

Pavel Bucek
Pavel Bucek

Reputation: 5324

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

Upvotes: 24

krishbhagya
krishbhagya

Reputation: 61

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>

Upvotes: 6

Related Questions