简体   繁体   English

春季在Jersey应用程序的自定义消息正文编写器

[英]Custom Message Body Writer for Jersey Application in Spring

I have a Rest Api that uses Spring MVC and Jersey 我有一个使用Spring MVC和Jersey的Rest Api

@GET
@Path("/hello")
@Produces(MediaType.APPLICATION_JSON)
public List<AccountEntity> hello() {
    return repository.findAll();

}

This Method is failing with the following error always 此方法始终失败,并出现以下错误

SEVERE: A message body writer for Java class java.util.ArrayList, and Java type java.util.List<net.viralpatel.spring.controller.AccountEntity>, and MIME media type application/json was not found.

My Gradle Dependencies 我的Gradle依赖

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile group: 'org.springframework', name: 'spring-webmvc', version: '4.3.9.RELEASE'
    compile group: 'org.springframework', name: 'spring-tx', version: '4.3.9.RELEASE'
    compile group: 'org.springframework.data', name: 'spring-data-jpa', version: '1.11.4.RELEASE'
    compile group: 'org.hibernate', name: 'hibernate-entitymanager', version: '5.2.10.Final'
    compile "javax.servlet:javax.servlet-api:3.0.1"
    compile "javax.servlet:jstl:1.2"
    compile 'org.glassfish.grizzly:grizzly-http-servlet-server:2.3.11@jar'
    compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.6'
    compile group: 'com.sun.jersey.contribs', name: 'jersey-spring', version: '1.19.4'

}

I tried adding 我尝试添加

compile group: 'org.glassfish.jersey.media', name: 'jersey-media-moxy', version: '2.26-b06'

But then the error appeared as javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder; 但是随后错误显示为javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;

我的项目结构

Update After adding jackson dependency 添加杰克逊依赖项后更新

caused by: com.sun.jersey.api.MessageException: A message body writer for Java class java.util.ArrayList, and Java type java.util.List<net.viralpatel.spring.controller.AccountEntity>, and MIME media type application/json was not found.

You have to add jersey-json dependency instead of moxy or jackson : 您必须添加jersey-json依赖关系,而不是moxyjackson

compile group: 'com.sun.jersey', name: 'jersey-json', version: '1.19.4'

This dependency already contains jackson in it with other required dependencies. 该依赖项已经包含jackson以及其他必需的依赖项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 泽西利用错误的邮件正文编写程序提供程序 - Jersey Utilizing Wrong Message Body Writer Provider 找不到Neo4j Cypher Java Jersey消息正文编写器 - Neo4j Cypher Java Jersey Message body writer not found 使用泽西(Jersey)开机自检以服务-“未找到消息正文编写器...” - Using Jersey to POST to service - “A message body writer … was not found” RESTEasy无法识别自定义消息正文编写器 - RESTEasy doesn't recognize custom message body writer Jersey客户端多部分/表单数据消息正文编写器异常 - Jersey Client multi-part/form-data message body writer exception com.sun.jersey.spi.container.ContainerResponse:Java类的消息正文编写器 - com.sun.jersey.spi.container.ContainerResponse: A message body writer for Java class 我的REST API(使用Jersey)无法找到持久实体(使用OpenJPA)的消息正文编写器(用于JSON)。 - My REST API (using Jersey) cannot find a message body writer (for JSON) for a persisted entity (using OpenJPA). jersey.api.MessageException消息正文编写器和MIME媒体类型text / xml未找到 - jersey.api.MessageException message body writer and MIME media type text/xml not found 无法为Spring jersey应用程序创建自定义错误 - Not able to create custom error for Spring jersey application 引发WebApplicationException时出错:com.sun.jersey.api.MessageException:找不到Java类java.util.HashMap的消息正文编写器 - error while throwing WebApplicationException : com.sun.jersey.api.MessageException: A message body writer for Java class java.util.HashMap not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM