在Spring Data REST中,我正在使用
ResourceProcessor
创建自定义链接:@Component
public class ServiceInstanceProcessor
implements ResourceProcessor<Resource<ServiceInstance>> {
@Override
public Resource<ServiceInstance> process(Resource<ServiceInstance> resource) {
Long id = resource.getContent().getId();
ServiceInstanceController controller =
methodOn(ServiceInstanceController.class);
resource.add(linkTo(controller.getNodeSummary(id))
.withRel("nodeSummary"));
resource.add(linkTo(controller.getHealthBreakdown(id))
.withRel("healthBreakdown"));
resource.add(linkTo(controller.getRotationBreakdown(id))
.withRel("rotationBreakdown"));
return resource;
}
}
然而,生成的链接不包括基本路径,尽管我已将控制器标记为@BasePathAwareController
,并且默认链接确实包括基本路径:
{
...
"_links" : {
"self" : {
"href" : "http://localhost:8080/api/serviceInstances/101"
},
"serviceInstance" : {
"href" : "http://localhost:8080/api/serviceInstances/101{?projection}",
"templated" : true
},
"nodeSummary" : {
"href" : "http://localhost:8080/serviceInstances/101/nodeSummary"
},
"healthBreakdown" : {
"href" : "http://localhost:8080/serviceInstances/101/healthBreakdown"
},
"rotationBreakdown" : {
"href" : "http://localhost:8080/serviceInstances/101/rotationBreakdown"
},
...
}
我需要在链接中显示基础路径,还有其他需要做的吗?