我正在使用Spring HATEOAS(0.16.0.RELEASE)构建Spring REST应用程序,我希望JSON链接输出如下所示:

_links: {
   self: {
     href: "https://<ip>/api/policies/321"
   }
}

虽然它呈现为:
   "links":
      [{
       "rel":"self",
       "href":"http://<ip>/api/policies/321"
      }]

我正在使用HATEOAS ResourceResourceAssembler

为什么我得到这种格式而不是其他格式?我该如何更改?

最佳答案


@Configuration
@EnableWebMvc
@EnableSpringDataWebSupport
@EnableHypermediaSupport(type = { HypermediaType.HAL })
@ComponentScan(basePackages = {
        "com.jiwhiz.rest"
})
public class WebConfig extends WebMvcConfigurerAdapter {
    @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer c) {
        c.defaultContentType(MediaTypes.HAL_JSON);
    }
}



引用:袁吉的Design and Build RESTful API with Spring HATEOAS

10-08 00:22