Spring-Hateoas:创建新链接的例外情况 [英] Spring-Hateoas: exception in creating a new link
本文介绍了Spring-Hateoas:创建新链接的例外情况的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
概述:
我将基于 Spring-Hateoas-Doc 发送到JSON响应:
I am going to add a new link based on Spring-Hateoas-Doc to the JSON response by using the following command:
linkTo(methodOn(ProductRepository.class).findOne(10L)).withRel("product");
问题:
但是我遇到以下异常:
java.lang.IllegalArgumentException: 'uriTemplate' must not be null
如果有人能建议我找到真正的解决方案,我将不胜感激。
So I would be grateful if anyone could suggest me a genuine solution.
推荐答案
我发现了这个问题。因为我的处理器类不是休息控制器,所以提出了这个问题。
为了解决这个问题,我使用了entityLinks,如下所示:
I found the issue. As I my processor class is not a rest controller, this issue has been raised. To solve it , I used the entityLinks instead, as follows:
@Controller
public class StockMovementsProcessor implements ResourceProcessor<Resource<StockMovementsProjection>> {
@Autowired
private EntityLinks entityLinks;
@Override
public Resource<StockMovementsProjection> process(Resource<StockMovementsProjection> stockMovementsProjectionResource) {
StockMovementsProjection stockMovementsProjection = stockMovementsProjectionResource.getContent();
stockMovementsProjectionResource.add(entityLinks.linkFor(Product.class).slash(10L).withRel("product"));
return stockMovementsProjectionResource;
}
}
它为我创建了以下链接:
And it created the following link for me:
http://localhost/products/10
这篇关于Spring-Hateoas:创建新链接的例外情况的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文