I want to create a Link to a resource within a Spring Data REST Repository. I know that we can use ControllerLinkBuilder.linkTo
method to create links to MVC controllers. As far is I understand Spring Data REST creates MVC controllers out of our Repository interfaces. But if I use
Instance createdInstance = instanceRepository.save(instance);
Link link = linkTo(InstanceRepository.class).slash(createdInstance.getId()).withSelfRel();
to create the link, I just get http://localhost:8080/2
(without the Repository path). Nothing changes if I specify the path explicitly with the @RepositoryRestResource
at the Repository.
Of course I could just create the link explicitly, but I don't want to repeat myself.
public interface InstanceRepository extends CrudRepository<Instance, Long> {
}
Any advice on what I could do to resolve this issue without having to violate DRY principles?