我根据编写一个简单的REST API 这个弹簧引导教程.在我的本地开发机器(Ubuntu 15.04和Windows 8.1)上,一切都像魅力一样.
我有一个旧的32位Ubuntu 12.04 LTS服务器,我想要部署我的REST服务.
启动日志没问题,但是一旦我向/ user/{id}端点发送GET请求,我就会收到以下错误:
java.lang.IllegalArgumentException: No converter found for return value of type: class ch.gmazlami.gifty.models.user.User
Run Code Online (Sandbox Code Playgroud)
然后在堆栈跟踪中:
java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.LinkedHashMap
Run Code Online (Sandbox Code Playgroud)
整个堆栈跟踪都发布在这里.
我查看了一些引用此错误的答案,但这些似乎并不适用于我的问题,因为我使用的是Spring-Boot,没有任何xml配置.
受影响的控制器是:
@RequestMapping(value = "/user/{id}", method = RequestMethod.GET)
public ResponseEntity<User> getUser(@PathVariable Long id){
try{
return new ResponseEntity<User>(userService.getUserById(id), HttpStatus.OK);
}catch(NoSuchUserException e){
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.这是非常奇怪的,因为完全相同的东西在其他机器上工作.
提前致谢!
如果有可能Stream从春天回来,我很好奇RestController
@RestController
public class X {
@RequestMapping(...)
public Stream<?> getAll() { ... }
}
Run Code Online (Sandbox Code Playgroud)
做这样的事情可以吗?我尝试过,Spring返回除了流的值以外的其他内容.
我要一直回来List<?>吗?
我正在使用Spring Boot和Web依赖创建一个简单的休息控制器.我试图将JSON主体反序列化为只有3个字段的测试POJO,但是当我尝试发出POST请求时,服务器响应500错误,我在控制台中得到的错误是:
.w.s.m.s.DefaultHandlerExceptionResolver : Failed to write HTTP message: org.springframework.http.converter.HttpMessageNotWritableException: No converter found for return value of type: class java.util.LinkedHashMap
Run Code Online (Sandbox Code Playgroud)
我写的所有代码如下:
EmailApplication.java:
package com.test.email.app;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(basePackages = { "com.test.email" })
public class EmailApplication {
public static void main(String[] args) {
SpringApplication.run(EmailApplication.class, args);
}
@Bean
public CommandLineRunner commandLineRunner(ApplicationContext ctx) {
return args -> {
System.out.println("----- You're up and running with test-email-app! -----");
};
}
}
Run Code Online (Sandbox Code Playgroud)
EmailController.java:
package com.test.email.controller;
import …Run Code Online (Sandbox Code Playgroud) 我上过课了Spring Boot,它完美无缺.但是,如果我想返回一组对象呢?我试着做这个,但它不工作.我该怎么做才能正确?
有一个对象(它的工作原理):
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue = "World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
Run Code Online (Sandbox Code Playgroud)
有很多对象(它不起作用):
@RequestMapping(value = "/greeting", method = RequestMethod.GET, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Greeting> greeting() {
Greeting greeting1 = new Greeting(1, "One");
Greeting greeting2 = new Greeting(2, "Two");
List<Greeting> list = new ArrayList<>();
list.add(greeting1);
list.add(greeting2);
return list;
}
Run Code Online (Sandbox Code Playgroud)