I try to create rest controller which return all products. I want to use CompletableFuture to return list with product.
I have async request to spring data
@Async
@Query("select product from Product product")
CompletableFuture<List<Product>> findAllAsync();
and controller
@Async
@RequestMapping(path = "/products", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody
CompletableFuture<List<ProductData>> loadAllProducts2(){
return this.products.findAllAsync()
.thenApplyAsync(Collection::stream)
.thenApplyAsync(s -> s.map(Product::data))
.thenApplyAsync(s -> s.collect(Collectors.toList()));
}
ProgramData is simple DTO:
public final class ProductData {
private final String name;
private final String label;
public ProductData(String name, String label) {
this.name = name;
this.label = label;
}
public String getName() {
return this.name;
}
public String getLabel() {
return this.label;
}
}
Spring return nothing, in log output is :
o.s.b.a.e.mvc.EndpointHandlerMapping : Did not find handler method for [/products]
Any ideas what's wrong ?