java - 尝试通过rest访问jpa数据时获取 "No mapping found for HTTP request with URI [/system/people]..."

标签 java spring spring-mvc spring-data-rest

这是我的存储库:

@RepositoryRestResource(collectionResourceRel = "people", path = "people") public interface PersonRepo extends PagingAndSortingRepository<Person, Long> { List<Person> findByName(@Param("name") String name); }

http://localhost:8080/system/people是我要访问的内容,其中“http://localhost:8080/system ”是 spring MVC 项目的基本 url

最佳答案

根据 http://docs.spring.io/spring-data/rest/docs/2.3.0.RELEASE/reference/html/#getting-started.introduction 我已经找到了解决方案,我添加了一个用于数据访问配置的类:

@配置 公共(public)类CustomizedRestMvcConfiguration扩展RepositoryRestMvcConfiguration { @覆盖 公共(public) RepositoryRestConfiguration config() { RepositoryRestConfiguration config = super.config(); config.setBasePath("/api"); 返回配置; } }

此外,我还在我的 Spring 应用程序配置类中添加了 @Import(CustomizedRestMvcConfiguration.class) 。现在每当我执行 http://localhost:8080/system/api/people调用,可以检索数据库条目。

关于java - 尝试通过rest访问jpa数据时获取 "No mapping found for HTTP request with URI [/system/people]...",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30283492/

相关文章:

spring-mvc - Spring @RestController 没有通过响应设置 cookie

java - 无法使用 REST API Controller 在服务器端检索 url 参数

java - 如何使用 Mongodb java 获取文档数组?

java - 我如何知道 url 导致调用 portlet spring mvc liferay 的 @RenderMapping render() 方法?

java - 如何在 Intellij IDEA 13.1 中使用 Maven 结构创建 Spring MVC 应用程序?

java - 如何通过向其传递运行时参数来使用命令模式

java - Spring 错误 : BeanNotOfRequiredTypeException

java - 从FTP下载时如何检查文件是否存在

spring - 使用 Spring Data MongoDB 中的 MongoTemplate 进行查找查询时仅投影某些字段?

java - 如何有效地拆分 ServletRequest .getParameterMap()? [Spring MVC,ServletRequest]