首页 > 解决方案 > @RepositoryRestResource 不起作用 Spring boot 2.2.1.RELEASE。运行时发生错误 RegionRepository 必须只包含单个路径段

问题描述

@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-data-rest 中定义名称为“repositorySearchController”的 bean 创建错误-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 配置的路径/区域必须只包含一个路径段!嵌套异常是 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 配置的路径/区域必须只包含一个路径段!嵌套异常是 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 配置的路径/区域必须只包含一个路径段!在类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.rest.core.mapping.RepositoryResourceMappings]:工厂方法“resourceMappings”抛出异常;嵌套异常是 java.lang.IllegalStateException:为 uz.pdp.prof.repository.RegionRepository 配置的路径/区域必须只包含一个路径段!在类路径资源 [org/springframework/data/rest/webmvc/config/RepositoryRestMvcConfiguration.class] 中定义:通过工厂方法进行 Bean 实例化失败;嵌套异常是 org.springframework.beans.BeanInstantiationException:无法实例化 [org.springframework.data.rest.core.mapping.RepositoryResourceMappings]:工厂方法“resourceMappings”抛出异常;嵌套异常是 java.lang.IllegalStateException:为 uz.pdp.prof.repository.RegionRepository 配置的路径/区域必须只包含一个路径段!resourceMappings 抛出异常;嵌套异常是 java.lang.IllegalStateException:为 uz.pdp.prof.repository.RegionRepository 配置的路径/区域必须只包含一个路径段!resourceMappings 抛出异常;嵌套异常是 java.lang.IllegalStateException:为 uz.pdp.prof.repository.RegionRepository 配置的路径/区域必须只包含一个路径段!

标签: javaspringhibernatespring-bootspring-data-rest

解决方案


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


推荐阅读