Spring HATEOAS provides the handy ControllerLinkBuilder
to create links to controller methods, which will be added as hrefs in the JSON/XML returned to a client. For instance:
resource.add(linkTo(methodOn(FooController.class)
.findFoo(entity.getClient().getId()))
.withRel("show"));
... might generate JSON a bit like:
{
"name":"foo",
"links":[
{"rel":"show","href":"http://111.11.11.111:28080/foos/1"}
]
}
However...
I tend to access my services through a reverse proxy. Which I guess most people probably would. This lets me have multiple services running on different ports, but lets me access them all through the same base URL. Unfortunately, accessing through a proxy means that the URL being generated by Spring HATEOAS is not a URL which is valid for accessing the resource.
Now I could just hard-code the links, but that's rather fragile. Having the ControllerLinkBuilder
generate URLs based on my controller @RequestMapping
configuration is valuable to me, as it avoids the risk of my links getting out of sync with reality.
So I was wondering whether there's a property somewhere that I could use to force the host and port values. I'm using Spring Boot, so ideally a property that I could add to the application.properties
file in each environment.
Note:
As this issue seems to be caused by a bug in Spring, I should probably point out that I'm using Spring Boot 1.0.2.RELEASE.