本文介绍了球衣添加jersey- *依赖项时不存在WebApplication提供程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Spring& Jersey应用程序,非常适合通过简单的Resource消费请求.但是,我想返回一个JSON响应-包含对象的简单JSON序列化.为此,我为jersey-json添加了一个maven依赖项.但是,一旦添加此依赖项,服务器启动时就会出现此错误:

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;
    }
}

扫描对象是一个简单的实体Bean对象.

A Scan object is a simple Entity Bean object.

mvn依赖项是:

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

有人知道为什么我可能会收到No WebApplication provider is present异常吗?关于如何解决该问题有任何想法吗?

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

谢谢

推荐答案

您还需要在类路径上也有jersey-server jar.并且您需要确保所有jar都来自相同版本,否则Jersey的运行时将无法使用提供的类.

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.

另外(很可能在这里不相关,但是..)模块结构最近发生了变化-servlet依赖项被分离到新模块中.因此,如果您使用的是servlet,则可能需要依赖jersey-servlet(取决于jersey-server).

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

这篇关于球衣添加jersey- *依赖项时不存在WebApplication提供程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 16:09