我在 Repository 接口(interface)上使用 @RepositoryResource 注释,代码如下:
@RepositoryRestResource(collectionResourceRel = "rest", path = "rest")
public interface HoliDayRepository extends CrudRepository<HoliDayEntity, Integer> {
HoliDayEntity findOne(Integer id);
}
我还在 Controller 类中添加了 RequestMapping("rest)
@RestController
@RequestMapping("/rest")
public class DayController {}
但是当我启动 Spring Boot 应用程序并尝试此链接时:http://localhost:8080/rest我在构建应用程序时也遇到 404 错误,我有 ResourceNotFoumd 异常,我应该如何管理这些错误?
最佳答案
使用 Spring Boot,您不需要创建自己的 Controller ;还要确保您的 Web 应用程序映射与用于 Spring 数据的映射不同,例如您可以在 application.properties
spring.data.rest.base-path:/api< 中设置
看看这个例子:
public interface PersonRepository extends JpaRepository<Person, UUID> {
List<Person> findByAddress(String address);
}
仅使用此代码,您应该能够访问此处的 spring 数据存储库:http://localhost:8080/api此处的人员端点 http://localhost:8080/api/person
看看这个教程:https://spring.io/guides/tutorials/react-and-spring-data-rest/或者这个例子:https://github.com/Paizo/SpringBootCamelStreamsExample
关于java - 无法在 Spring 服务中使用 ReposiotryResource 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49507239/