【发布时间】:2016-11-08 06:40:31
【问题描述】:
我使用其对应的实体存储库编写了一个自定义RepositoryRestController。在此 url 上执行请求时,查询正在我的控制台中运行,但 url 返回 404。我还能够在日志中看到此 url 的 requestHandlerMapping。参考我下面的代码sn-p。
存储库:
@RepositoryRestResource
public interface FooRepository extends BaseRepository<Foo, Integer> {
@RestResource(exported = false)
List<Foo> findByName(String name);
}
控制器:
@RepositoryRestController
public class FooResource {
@Aurowired
FooRepository fooRepository;
@Autowired
RestApiService restApiService;
@RequestMapping(value = "/foos/search/byApiName", method = GET)
public ResponseEntity<?> findByApiName(String name) {
List<String> apiNames = restApiService.getNameLike(name);
List<Foo> fooList = fooRepository.findByName(name);
List<String> fooNames = // list of names from fooList
...
System.out.println("FETCHING apiNames");
return apiNames;
}
当我执行以下 curl 命令时
curl -X GET http:localhost:8080/foos/search/byApiName
响应返回 404 错误。我不知道为什么。但他的打印输出语句正在控制台中打印。
@hat 我在这里做错了吗?
【问题讨论】:
-
Spring 中典型的 404 错误意味着您缺少上下文根。并且您在没有它的情况下调用该服务。尝试在端口号之后和
/foos之前添加它。通常是项目的名称。例如http://localhost:8080/SpringWeb/foos/search/byApiName
标签: controller spring-data-jpa spring-data-rest