java - @RepositoryRestResource 在 Spring Boot 2.2.1.RELEASE 中不起作用。运行时出现错误 RegionRepository 必须只包含一个路径段

标签 java spring hibernate spring-boot spring-data-rest

@RepositoryRestResource(path = "/region", collectionResourceRel = "list", excerptProjection = CustomRegion.class)
public interface RegionRepository extends JpaRepository<Region, Integer> {
}

数据休息类
@SpringBootApplication
public class ProfUzApplication {
    public static void main(String[] args) {
        SpringApplication.run(ProfUzApplication.class, args);
    }
}

主跑类

发生错误

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'repositorySearchController' defined in URL [jar:file:/C:/Users/saidk/.m2/repository/org/springframework/data/spring-data-rest-webmvc/3.2.1.RELEASE/spring-data-rest-webmvc-3.2.1.RELEASE.jar!/org/springframework/data/rest/webmvc/RepositorySearchController.class]: Unsatisfied dependency expressed through constructor parameter 1; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityLinks' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.webmvc.support.RepositoryEntityLinks]: Factory method 'entityLinks' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'resourceMappings' defined in class path resource [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.data.rest.core.mapping.RepositoryResourceMappings]: Factory method 'resourceMappings' threw exception; nested exception is java.lang.IllegalStateException: Path /region configured for uz.pdp.prof.repository.RegionRepository must only contain a single path segment!

最佳答案

您必须在@RepositoryRestResource 中提及 path='endpoint name' 而不使用 '/'。您必须使用 @RepositoryRestResource(path = "region" ),它是直接的 spring MVC 在 创建 RESTful 端点/region

关于java - @RepositoryRestResource 在 Spring Boot 2.2.1.RELEASE 中不起作用。运行时出现错误 RegionRepository 必须只包含一个路径段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58830824/

相关文章:

java - 序列化和反序列化

spring - Spring Data JPA 中的订单按日期描述限制

Spring Java 配置 - @DependsOn 链接

java - 将 @ElementCollection 映射到同一个表

java - 未调用 Onsavedinstancestate 时写入 outState

java - 获取通用类型的通用类型

java - 将结果集的行存储在字符串数组中

java - Spring框架中的ClassNotFoundException

java - 由于 MySQLSyntaxErrorException : Unknown database 'dbname' error,无法通过 hibernate 连接到 MySQL 数据库

java - Hibernate多对多: Criteria for looking up all class A which DO NOT contain class B