【问题标题】:@RepositoryRestResource did not work Spring boot 2.2.1.RELEASE. while running occured error RegionRepository must only contain a single path segment@RepositoryRestResource 不起作用 Spring boot 2.2.1.RELEASE。运行时发生错误 RegionRepository 必须只包含单个路径段
【发布时间】:2019-11-13 05:28:34
【问题描述】:
@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:在 URL [jar:file:/C:/Users/saidk/.m2/repository/org/springframework/data/spring- 中定义名称为“repositorySearchController”的 bean 创建错误data-rest-webmvc/3.2.1.RELEASE/spring-data-rest-webmvc-3.2.1.RELEASE.jar!/org/springframework/data/rest/webmvc/RepositorySearchController.class]:通过构造函数参数表示的不满足的依赖关系1个;嵌套异常是 org.springframework.beans.factory.BeanCreationException:在类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义名称为“entityLinks”的 bean 创建时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.rest.webmvc.support.RepositoryEntityLinks]:工厂方法 'entityLinks' 抛出异常;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义的名称为“resourceMappings”的 bean 时出错:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.rest.core.mapping.RepositoryResourceMappings]:工厂方法“resourceMappings”抛出异常;嵌套异常是 java.lang.IllegalStateException:为 uz.pdp.prof.repository.RegionRepository 配置的路径/区域必须只包含一个路径段!

【问题讨论】:

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


    【解决方案1】:

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

    创建 RESTful 端点

    【讨论】:

      【解决方案2】:

      出现问题是因为您使用“/”定义了路径。 Spring 不允许我们定义像“/api/v1/my_entity”这样的组合路径。只需从路径中删除“/”即可。

      【讨论】:

        【解决方案3】:

        几天前我创建了一个基于 2.2.2 的新项目并遇到了同样的问题。

        经过几次尝试,修复它的方法是在 path 和 collectionResourceRel 中使用相同的值。在您的情况下,请尝试在路径和 collectionResourceRel 中使用“区域”。

        【讨论】:

        • 您的代码中还有一个问题是 JpaRepository,我认为您应该使用 Region 实体而不是 RegionRepository。
        猜你喜欢
        • 2020-03-22
        • 1970-01-01
        • 1970-01-01
        • 2014-06-17
        • 1970-01-01
        • 1970-01-01
        • 2023-02-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多