【发布时间】:2015-12-11 12:26:02
【问题描述】:
我正在使用 Jersey 开发 JAX-RS,我有一个向客户端返回数据的资源类,我能够返回 xml 数据作为响应,但是当我尝试返回 JSON 时它不起作用,我得到了低于错误
我的 POM.xml 有问题吗?
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.amdocs.login.login</groupId>
<artifactId>login</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>login</name>
<build>
<finalName>login</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<inherited>true</inherited>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>${jersey.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet-core</artifactId>
<!-- use the following artifactId if you don't need servlet 2.x compatibility -->
<!-- artifactId>jersey-container-servlet</artifactId -->
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-moxy</artifactId>
</dependency>
</dependencies>
<properties>
<jersey.version>2.16</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
【问题讨论】:
-
如果你切换到杰克逊会发生什么?
jersey-media-json-jackson(替换jersey-media-moxy)? -
我用 jersey-media-json-jackson 替换了它,但仍然遇到同样的问题
-
是否有任何 Eclipse 日志说明它无法从 .m2 读取的实际原因? Eclipse 中的 Maven 项目还有其他问题吗?我想知道是否可能是权限问题。我想我以前从未见过这个错误。
-
Glassfish 应该是一个完整的 EE 容器,从而为 REST 服务启动所有需要的依赖项。您应该在您的 pom 中将它们声明为“提供”
标签: json rest maven jax-rs jersey-2.0