spring - [org.springframework.web.HttpMediaTypeNotAcceptableException:找不到可接受的表示]
问题描述
我是 Spring data jpa 的新手,试图创建一个简单的 spring boot - data jpa-hibernate 应用程序。2021-04-03 20:24:40.478 WARN 33252 --- [nio-8081-exec-1] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation]
当我点击 url 时,我正在进入我的控制台下面http://localhost:8081/users
是我的控制器代码,
@RestController
public class UserController {
@Autowired
private UserService userService;
@GetMapping(value="/users")
public List<User> getAllUsers() {
List<User> result = userService.getAllUsers();
return result;
}
}
服务等级——
@Service
public class UserService {
@Autowired
private UserRepository userRepository;
public List<User> getAllUsers() {
List<User> r = (List<User>) userRepository.findAll();
return r;
}
}
存储库接口-
@Repository
public interface UserRepository extends CrudRepository<User, Integer>{
}
我已经浏览了各种在线可用的解决方案,但似乎没有任何效果。在此先感谢您的帮助。
解决方案
您的浏览器用于发送请求的“接受”标头存在一些问题。你能包括你的http请求浏览器跟踪吗?
推荐阅读
- python - 无法在具有 GPU 的机器上安装没有 CUDA 支持的 Keras MXNet
- c# - .CS 文件中的 DataGrid 千位分隔符 WPF
- android-studio - Check Image view is empty or not?
- javascript - 如何减去asp文本框值并将结果放入asp标签
- r - 在rcpp中按名称更改向量元素
- roku - 在 Roku 频道播放 Youtube 视频
- python-3.x - 使用 pyplot 和 Pandas 在 Barchart 中标记条形失败
- javascript - 在隐身窗口中打开 URL
- swift - 将多个闭包作为参数快速传递给函数
- kubernetes - Vault 为键提供旧值和新值