相关疑难解决方法(0)

Spring MVC - HttpMediaTypeNotAcceptableException

当与Spring MVC和JSON一起使用时,我一直收到AJAX请求的HttpMediaTypeNotAcceptableException错误.错误的完整堆栈跟踪是..

 org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.writeWithMessageConverters(AnnotationMethodHandlerAdapter.java:1032)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.handleResponseBody(AnnotationMethodHandlerAdapter.java:972)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.getModelAndView(AnnotationMethodHandlerAdapter.java:921)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:438)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:424)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:863)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:792)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:851)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:756)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
Run Code Online (Sandbox Code Playgroud)

我做的小google搜索显示请求应该包含类似"accept:application/json"的东西,它确实有..这里是来自firebug的请求标头..

Response Headers
Server  Apache-Coyote/1.1
Content-Type    text/html;charset=utf-8
Content-Length  2503
Date    Thu, 25 Aug 2011 21:00:05 GMT
Connection  close

Request Headers
Host    localhost:8080
User-Agent  Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.20) Gecko/20110803 Firefox/3.6.20 (.NET CLR 3.5.30729)
Accept  application/json, text/javascript, */*; q=0.01
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip,deflate
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive  115
Connection  keep-alive
X-Requested-With    XMLHttpRequest
Referer http://localhost:8080/legaldirectory/index.html
Cookie  JSESSIONID=5C97DA19AED4D5FA17F4A58470FAA93B
Run Code Online (Sandbox Code Playgroud)

现在我完全迷失在这里发生的事情......这里还有什么可能出错来解决这个错误......

spring json spring-mvc spring-json

43
推荐指数
7
解决办法
11万
查看次数

无法提取响应:没有为响应类型找到合适的HttpMessageConverter

我是Spring的新成员,并在Spring集成http模块中工作,以满足我的项目需求.我从出站网关发送请求作为http客户端.我正在尝试向服务器发起请求,服务器应该使用我的设置值返回消息有效负载.我正在将对象转换为JSON使用发送到服务器我正在从客户端(HttpClientDemo)向服务器端的入站网关发送请求,如下所示.为此,我将我的对象转换为JSON,然后在客户端转换为JSON字符串到对象,在那里执行一些简单的操作并将其发送回客户端(HttpClientDemo)但在此之前,我得到与之相关的异常HttpMessageConverter如下:

Exception in thread "main" org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class com.mycompany.MyChannel.model.FFSampleResponseHttp] and content type [text/plain;charset=UTF-8]
    at org.springframework.web.client.HttpMessageConverterExtractor.extractData(HttpMessageConverterExtractor.java:108)
    at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:784)
    at org.springframework.web.client.RestTemplate$ResponseEntityResponseExtractor.extractData(RestTemplate.java:769)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:549)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:517)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:462)
    at org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler.handleRequestMessage(HttpRequestExecutingMessageHandler.java:421)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:170)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:78)
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:101)
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:97)
    at org.springframework.integration.channel.AbstractSubscribablMyChannel.doSend(AbstractSubscribablMyChannel.java:77)
    at org.springframework.integration.channel.AbstractMessagMyChannel.send(AbstractMessagMyChannel.java:255)
    at org.springframework.integration.channel.AbstractMessagMyChannel.send(AbstractMessagMyChannel.java:223)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:114)
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:44)
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:93)
Run Code Online (Sandbox Code Playgroud)

请在下面找到相关代码:

客户端代码:HttpClientDemo.java

public class HttpClientDemo {

    private static Logger logger = Logger.getLogger(HttpClientDemo.class);
    public static void main(String[] args) {
        ApplicationContext context = …
Run Code Online (Sandbox Code Playgroud)

spring spring-integration

13
推荐指数
3
解决办法
9万
查看次数

Spring Rest 模板无法从 text/html 转换

春季休息模板引发了以下异常

org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [class [Lcom.flightsms.core.dto.AirlineResponseDTO;] and content type [text/html;charset=UTF-8]
Run Code Online (Sandbox Code Playgroud)

这是我的 json 响应

[
 {
  "airlineId": "1",
  "nameAirline": "American Airlines",
  "codeIataAirline": "AA",
  "iataPrefixAccounting": "1",
  "codeIcaoAirline": "AAL",
  "callsign": "AMERICAN",
  "type": "scheduled",
  "statusAirline": "active",
  "sizeAirline": "963",
  "ageFleet": "10.9",
  "founding": "1934",
  "codeHub": "DFW",
  "nameCountry": "United States",
  "codeIso2Country": "US"
 }
]
Run Code Online (Sandbox Code Playgroud)

dto类

@Data
public class AirlineResponseDTO {
  private String airlineId;
  private String nameAirline;
  private String codeIataAirline;
  private String iataPrefixAccounting;
  private String codeIcaoAirline;
  private String callsign; …
Run Code Online (Sandbox Code Playgroud)

rest spring json resttemplate

7
推荐指数
2
解决办法
1万
查看次数