Rest 为什么要获取HttpMediaTypeNotAcceptableException?
我有一个springboot rest控制器:Rest 为什么要获取HttpMediaTypeNotAcceptableException?,rest,spring-boot,Rest,Spring Boot,我有一个springboot rest控制器: @RestController public class UserController { @Autowired UserRepository userRepository; @RequestMapping(value = "/account/{userid:.+}", method = RequestMethod.GET) public HttpEntity<Account> getAccountByUser
@RestController
public class UserController {
@Autowired UserRepository userRepository;
@RequestMapping(value = "/account/{userid:.+}", method = RequestMethod.GET)
public HttpEntity<Account> getAccountByUserId(@PathVariable String userid) {
if(userid == null) {
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
Account user = userRepository.findOneByUserid(userid.toLowerCase());
if(user == null) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(user, HttpStatus.OK);
}
}
@RestController
公共类用户控制器{
@自动连线用户存储库用户存储库;
@RequestMapping(value=“/account/{userid:.+}”,method=RequestMethod.GET)
公共HttpEntity
这个调用非常有效,我收到一个带有可爱json的200状态代码:
但是这个电话
返回状态代码406,调试日志显示消息“org.springframework.web.HttpMediaTypeNotAcceptableException:找不到可接受的表示”
为什么以及如何修复它?谢谢。我猜Spring的内容协商正在启动。au-简单的测试方法是关闭内容协商,看看是否仍然存在错误。