Spring Boot生成文本/csv,找不到可接受的表示形式

Spring Boot生成文本/csv,找不到可接受的表示形式,spring,jhipster,Spring,Jhipster,我试图让我的Spring Boot应用程序返回accept=text/csv,我继续得到: org.springframework.web.HttpMediaTypeNotAcceptableException:无法 找到可接受的代表 我补充说: compile "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:${jackson_version}" compile "com.fasterxml.jackson.dataformat

我试图让我的Spring Boot应用程序返回
accept=text/csv
,我继续得到:

org.springframework.web.HttpMediaTypeNotAcceptableException:无法 找到可接受的代表

我补充说:

compile "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:${jackson_version}"
compile "com.fasterxml.jackson.dataformat:jackson-dataformat-csv:${jackson_version}"
对于我的
build.gradle
,我使用的不是SpringMVC

处理程序如下所示:

@RequestMapping(value = "/{id}/csv", method = RequestMethod.GET, produces = "text/csv")
    public List<RegistrationCode> exportToCsv(@ApiParam(name = "id", required = true, value = "string") @PathVariable String id, HttpServletResponse response) {

...
    String headerKey = "Content-Disposition";
    String headerValue = String.format("attachment; filename=\"%s\"",
        csvFileName);
    response.setHeader(headerKey, headerValue);
    response.setContentType("text/csv;charset=utf-8");
    return registrationCodes;
}
消息转换器:

public class CsvMessageConverter extends AbstractHttpMessageConverter<List<RegistrationCode>> {

}
我在这里找到了一些注册转换的说明:


我们用postman@GaëlMarziou完成了我的消息转换(我只是无法将其注册),我将发布该消息的标题。我不知道如果不使用Spring MVC,您可以使用@RequestMapping。有什么好处?你不能使用springfox来招摇过市,对吧?@GaëlMarziou正确,添加
@EnableWebMvc
或扩展
webmvc配置支持
,因为大多数答案都暗示这会破坏我的应用程序。对不起,我帮不上忙,你离JHipster生成的代码很远。
public class CsvMessageConverter extends AbstractHttpMessageConverter<List<RegistrationCode>> {

}
<util:list id="messageConverters">
    <bean class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter"
          p:objectMapper-ref="jsonObjectMapperFactory"/>
    <!--bean class="org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter"
          p:objectMapper-ref="xmlObjectMapperFactory"/-->
    <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
    <bean class="com.binding.CsvMessageConverter"/>
</util:list>
    //Adding the message converter
@Configuration
public class MyApplicationConfiguration {
    ...    
    @Bean
    public HttpMessageConverters customConverters() {
        return new HttpMessageConverters(new CsvMessageConverter());
    }
}