Java 无法在spring服务中使用ReposiotryResource终结点

Java 无法在spring服务中使用ReposiotryResource终结点,java,rest,spring-boot,Java,Rest,Spring Boot,我在我的repository接口上使用@RepositoryResource注释,代码如下: @RepositoryRestResource(collectionResourceRel = "rest", path = "rest") public interface HoliDayRepository extends CrudRepository<HoliDayEntity, Integer> { HoliDayEntity findOne(Integer id); }

我在我的repository接口上使用@RepositoryResource注释,代码如下:

@RepositoryRestResource(collectionResourceRel = "rest", path = "rest")
public interface HoliDayRepository extends CrudRepository<HoliDayEntity, Integer> {

    HoliDayEntity findOne(Integer id);

}

但当我启动spring boot应用程序并尝试以下链接时:我在构建应用程序时也遇到了404错误,我有ResourceNotFoumd异常。我应该如何管理这些错误?

您需要一个方法,当您到达端点时应该调用该方法

请尝试以下内容,并检查弹簧示例:

编辑:
正如Gimby所指出的,这在使用@RepositoryRestResource时不适用。代码和附带的教程都是指通过使用spring boot创建控制器来创建新的REST服务,您不需要创建自己的控制器;还要确保您的web应用程序映射与用于spring数据的映射不同,例如,您可以在application.properties spring.data.rest.base-path:/api中设置

看看这个例子:

public interface PersonRepository extends JpaRepository<Person, UUID> {
    List<Person> findByAddress(String address);
}
只要使用这段代码,您就应该能够访问这里的spring数据存储库:以及这里的person端点


请看本教程:或此示例:

在中,未创建任何控制器。这个想法是Spring为你做的。Hi@Gimby,我在没有requestMapping的情况下尝试了这个方法,但是结果是一样的,我无法得到这个端点。你在应用程序启动期间看到Spring MVC初始化的url了吗,可能添加了一些前缀,例如myApp/rest???PS.尝试更改日志级别以查找spring扫描的bean和控制器。当我使用culr时,我只得到以下链接:{{u links:{profile:{href:}}}},因此在正在使用的RepositoryRestResource注释中不能有任何前缀值。如果不使用该注释,您的答案将适用。
@Autowired
private HoliDayRepository holiDayRepository; //your repository to execute the query

@GetMapping(value = "/{id}")//you can use @RequestMapping(method = RequestMethod.GET, value = "/{holida}")
public ResponseEntity<HoliDayEntity > getHolidayById(@PathVariable("id") Integer id) {

    HoliDayEntity holiDayEntityresponse = productOperations.getProductById(id);
    return new ResponseEntity<>(holiDayEntityresponse , HttpStatus.OK);
}
public interface PersonRepository extends JpaRepository<Person, UUID> {
    List<Person> findByAddress(String address);
}