首页 > 解决方案 > [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>{

}

我已经浏览了各种在线可用的解决方案,但似乎没有任何效果。在此先感谢您的帮助。

标签: springspring-boothibernatespring-data-jpa

解决方案


您的浏览器用于发送请求的“接受”标头存在一些问题。你能包括你的http请求浏览器跟踪吗?


推荐阅读