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

M. *_*nov 5 java spring hibernate spring-data-rest spring-boot

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

数据休息类

@SpringBootApplication
public class ProfUzApplication {
    public static void main(String[] args) {
        SpringApplication.run(ProfUzApplication.class, args);
    }
}
Run Code Online (Sandbox Code Playgroud)

主跑课

发生错误

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 配置的路径 /region 必须只包含一个路径段!嵌套异常是 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 配置的路径 /region 必须只包含一个路径段!嵌套异常是 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 配置的路径 /region 必须只包含一个路径段!在类路径资源[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 配置的路径 /region 必须只包含一个路径段!在类路径资源[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 配置的路径 /region 必须只包含一个路径段!resourceMappings 抛出异常;嵌套异常是 java.lang.IllegalStateException:为 uz.pdp.prof.repository.RegionRepository 配置的路径 /region 必须只包含一个路径段!resourceMappings 抛出异常;嵌套异常是 java.lang.IllegalStateException:为 uz.pdp.prof.repository.RegionRepository 配置的路径 /region 必须只包含一个路径段!

小智 6

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