12

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

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
idbentley
  • 4,188
  • 3
  • 34
  • 50
  • are you sure that you have jersey-server on classpath as well? Remember, all jersey modules must have exactly same version - they won't be able to find each other providers if this condition is not met. – Pavel Bucek Jan 03 '12 at 20:24
  • Thanks Pavel - go ahead and make this comment an answer, and I'll accept it. – idbentley Jan 04 '12 at 19:48

2 Answers2

24

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

rogerdpack
  • 62,887
  • 36
  • 269
  • 388
Pavel Bucek
  • 5,304
  • 27
  • 44
  • 2
    Thank you! I had this with embedded neo4j server, which broke when I added a dependency which included a json client. For example - http://lists.neo4j.org/pipermail/user/2011-November/013368.html – Stewart Apr 20 '13 at 23:34
  • Besides, jersey-servlet 1.17 produces the same problem. Use 1.17.1 instead. – Robin Loxley Nov 21 '13 at 08:50
6

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>
krishbhagya
  • 61
  • 1
  • 1