xml - 找不到消息正文作者
问题描述
以下是 iam 用于将 Java 对象作为 XML 返回的代码片段:
@Path("employeeinfo")
@Produces(MediaType.APPLICATION_XML)
public class MyResource {
@GET
public Employee getEmployee(@Context Request r) {
Employee emp = new Employee();
emp.setName("Name");
emp.setAge(30);
emp.setPlace("place");
return emp;
}
员工类是:
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement(name= "emp")
public class Employee {
public Employee() {}
private String name;
private int age;
private String place;
}
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>rest.learning</groupId>
<artifactId>RestWebservice</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>RestWebservice</name>
<build>
<finalName>RestWebservice</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.inject</groupId>
<artifactId>jersey-hk2</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>
</dependencies>
<properties>
<jersey.version>3.0.0-M1</jersey.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
就设置而言,一切都很好,但是当我评估邮递员的服务时,我得到了错误
"SEVERE: MessageBodyWriter not found for media type=application/xml, type=class rest.learning.Employee, genericType=class rest.learning.Employee."
我无法在这里检测到错误。我搜索了所有互联网但没有找到任何答案
解决方案
推荐阅读
- php - 如何在php中只获得一级目录名称
- stripe-payments - 如何通过 Stripe redirectToCheckout 函数传递元数据
- suitescript - 如何从带有某些字段来源的按钮导航到自定义记录?(suitescript 2.0)
- c++ - 为什么 QDialogButtonBox 标签的语言在设计和执行之间会发生变化?
- python - 有没有办法使用消息 ID 编辑特定消息。不和谐
- php - 通过 CSV 将自定义分类法导入 WooCommerce
- python - 以 10 为底的 int() 的 Django 无效文字:b'11 20:11:22'
- scala - 如何将一个或多个本地 .jar 文件中的类导入 Spark/Scala Notebook?
- python - 如何确保延迟等待 asyncio.wait(...) 的协程?
- java - 您将如何为采用 FileInputStream 的方法制作测试用例?