@RepositoryRestResource 没有工作 Spring 启动 2.2.1.RELEASE。 while 运行 occurred error RegionRepository must only contain a single path segment
@RepositoryRestResource did not work Spring boot 2.2.1.RELEASE. while running occured error RegionRepository must only contain a single path segment
@RepositoryRestResource(path = "/region", collectionResourceRel = "list", excerptProjection = CustomRegion.class)
public interface RegionRepository extends JpaRepository<Region, Integer> {
}
数据休息class
@SpringBootApplication
public class ProfUzApplication {
public static void main(String[] args) {
SpringApplication.run(ProfUzApplication.class, args);
}
}
主要运行class
发生错误
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!
我几天前基于 2.2.2 创建了一个新项目,但遇到了同样的问题。
经过几次尝试,修复它的方法是在path和collectionResourceRel中使用相同的值。在您的情况下,请尝试在路径和 collectionResourceRel 中使用 "region"。
出现此问题是因为您使用“/”定义了路径。 Spring 不允许我们定义像“/api/v1/my_entity”这样的组合路径。只需从您的路径中删除“/”即可。
您必须在 @RepositoryRestResource 中提及 path='endpoint name' 而无需使用“/”。您必须使用 @RepositoryRestResource(path = "region"),它是直接 spring MVC 在 /region[= 创建 RESTful 端点14=]
@RepositoryRestResource(path = "/region", collectionResourceRel = "list", excerptProjection = CustomRegion.class)
public interface RegionRepository extends JpaRepository<Region, Integer> {
}
数据休息class
@SpringBootApplication
public class ProfUzApplication {
public static void main(String[] args) {
SpringApplication.run(ProfUzApplication.class, args);
}
}
主要运行class
发生错误
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!
我几天前基于 2.2.2 创建了一个新项目,但遇到了同样的问题。
经过几次尝试,修复它的方法是在path和collectionResourceRel中使用相同的值。在您的情况下,请尝试在路径和 collectionResourceRel 中使用 "region"。
出现此问题是因为您使用“/”定义了路径。 Spring 不允许我们定义像“/api/v1/my_entity”这样的组合路径。只需从您的路径中删除“/”即可。
您必须在 @RepositoryRestResource 中提及 path='endpoint name' 而无需使用“/”。您必须使用 @RepositoryRestResource(path = "region"),它是直接 spring MVC 在 /region[= 创建 RESTful 端点14=]