严重:未找到 java.util.Vector 类的消息正文编写器,ContentType:application/xml
我有一个最小的 JAX-RS 应用程序。我试图生成 XML 响应,但出现以下异常。该资源应返回 Country 对象列表,但异常引用 Vector。我正在运行 TomEE Web Profile 9.0.0-M7 和 Jakarta Web Profile 9.1。
例外
Mar 04, 2022 12:33:42 PM org.apache.cxf.jaxrs.utils.JAXRSUtils logMessageHandlerProblem
SEVERE: No message body writer has been found for class java.util.Vector, ContentType: application/xml
应用
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
@ApplicationPath("/api")
public class RestApplication extends Application {
}
国家资源
@Path("/country")
public class CountryResource {
@GET
@Produces(MediaType.APPLICATION_XML)
public List<Country> getCountries() {
return Database.get().findCountries();
}
}
国家查询
public List<Country> findCountries() {
return em.createQuery("SELECT c FROM Country c ORDER BY c.countryName", Country.class).getResultList();
}
I have a minimal JAX-RS application. I am trying to produce an XML response, but instead I get the exception below. The resource should return a List of Country objects, but the exception refers to a Vector. I am running TomEE Web Profile 9.0.0-M7 and Jakarta Web Profile 9.1.
Exception
Mar 04, 2022 12:33:42 PM org.apache.cxf.jaxrs.utils.JAXRSUtils logMessageHandlerProblem
SEVERE: No message body writer has been found for class java.util.Vector, ContentType: application/xml
Application
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;
@ApplicationPath("/api")
public class RestApplication extends Application {
}
Country Resource
@Path("/country")
public class CountryResource {
@GET
@Produces(MediaType.APPLICATION_XML)
public List<Country> getCountries() {
return Database.get().findCountries();
}
}
Country query
public List<Country> findCountries() {
return em.createQuery("SELECT c FROM Country c ORDER BY c.countryName", Country.class).getResultList();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
国家/地区需要使用 XmlRootElement 注释进行注释。
Country needs to be annotated with an XmlRootElement annotation.