将 ResourceProcessor 迁移到 HATEOAS 1.0.0 M1

Migrating ResourceProcessor to HATEOAS 1.0.0 M1

在我当前的 Spring HATEOAS 0.25.1.RELEASE 项目中,我大量使用 ResourceProcessor 接口:

 @Bean
 public ResourceProcessor<Resource<Person>> personProcessor() {
    return new ResourceProcessor<Resource<Person>>() {
      @Override
      public Resource<Person> process(Resource<Person> resource) {
       resource.add(new Link("http://localhost:8080/people", "added-link"));
       return resource;
      }
    };
 }

如何将我的资源处理器迁移到 Spring HATEOAS 1.0.0 M1?

在SpringHATEOAS 1.0 M1中,很多类型和API都改变了命名约定。

在您的示例中,ResourceProcessor 现在是 RepresentationModelProcessorResource<T> 现在是 EntityModel<T>,像这样:

public RepresentationModelProcessor<EntityModel<Person>> personProcessor() {
return new RepresentationModelProcessor<EntityModel<Person>>() {
  @Override
  public EntityModel<Person> process(EntityModel<Person> entityModel) {
    entityModel.add(new Link("http://localhost:8080/people", "added-link"));
    return entityModel;
  }
};

}

查看完整的更改说明 here