Search code examples
spring-data-restspring-hateoas

How to add additional links to the root resource in Spring Data REST?


The spring-data-rest module automatically scans for all repositories in an app and lists them like this:

{
"_links" : {
    "demoRepository" : {
    "href" : "http://localhost/demoRepository{?page,size,sort}",
    "templated" : true
    }
}

However I have some resources that are not backed by a database and don't have repository classes.

How can I add simple resources that have their own controller classes into the above list. Right now the list does not reflect the whole REST api of my app.


Solution

  • You need to implement ResourceProcessor and then add Your custom links to RepositoryLinksResource. See https://stackoverflow.com/a/26118405/4090455