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:
我有一个简单的Spring & Jersey应用程序,它非常适合通过简单的资源使用请求。但是,我想返回一个JSON响应—包含对象的简单JSON序列化。为此,我添加了一个maven对jercy -json的依赖项。但是,一旦我添加了这个依赖项,我在服务器启动时就会得到这个错误:
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.
扫描对象是一个简单的实体Bean对象。
The mvn dependency is:
mvn依赖关系是:
<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?
有人知道我为什么会得到No WebApplication provider是present Exception吗?有什么想法吗?
Thanks
谢谢
2 个解决方案
#1
23
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.
您还需要在类路径中包含jersy -server jar。您需要确保所有的jar都来自同一个版本,否则Jersey运行时将不能使用提供的类。
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).
另外(很可能与此无关,但是..)模块结构最近发生了变化——servlet依赖关系被分离到新的模块中。因此,如果您正在使用servlet,您可能需要依赖于jersy -servlet(它依赖于jersey-server)。
#2
6
I am also had this issue. The issue was resolved by having same version for "jersey-json" and "jersey-servlet"maven dependencies.
我也有这个问题。通过为“jerfy -json”和“jersy -servlet”maven依赖项提供相同的版本,这个问题得到了解决。
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>
#1
23
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.
您还需要在类路径中包含jersy -server jar。您需要确保所有的jar都来自同一个版本,否则Jersey运行时将不能使用提供的类。
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).
另外(很可能与此无关,但是..)模块结构最近发生了变化——servlet依赖关系被分离到新的模块中。因此,如果您正在使用servlet,您可能需要依赖于jersy -servlet(它依赖于jersey-server)。
#2
6
I am also had this issue. The issue was resolved by having same version for "jersey-json" and "jersey-servlet"maven dependencies.
我也有这个问题。通过为“jerfy -json”和“jersy -servlet”maven依赖项提供相同的版本,这个问题得到了解决。
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>