相关疑难解决方法(0)

使用spring-boot-starter-web"无法找到可接受的表示"

我试图用来spring-boot-starter-web创建一个提供Java对象的JSON表示的休息服务.根据我的理解,这个boot-starter-web jar应该自动处理通过Jackson转换为JSON,但我得到了这个错误.

{ "timestamp": 1423693929568,
  "status": 406,
  "error": "Not Acceptable",
  "exception": "org.springframework.web.HttpMediaTypeNotAcceptableException",
  "message": "Could not find acceptable representation"
}
Run Code Online (Sandbox Code Playgroud)

我的控制器就是这个......

@RestController
@RequestMapping(value = "/media")
public class MediaController {
    @RequestMapping(value = "/test", method = RequestMethod.POST)
    public @ResponseBody UploadResult test(@RequestParam(value="data") final String data) {
      String value = "hello, test with data [" + data + "]"; 
      return new UploadResult(value);
    }

    @RequestMapping(value = "/test2", method = RequestMethod.POST)
    public int test2() {
        return 42;
    }

    @RequestMapping(value = "/test3", method = RequestMethod.POST)
    public …
Run Code Online (Sandbox Code Playgroud)

java spring json spring-mvc maven

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

标签 统计

java ×1

json ×1

maven ×1

spring ×1

spring-mvc ×1