title: Spring hateoas methodOn with inherited method
body: <p>I am trying to use Spring hateoas to resolve the URL of an inherited endpoint from an abstract controller.</p>
  
  <p>I think giving the code first will make the question easier to understand.</p>
  
  <p>Here is my abstract controller :</p>
  
  <pre><code>package com.stackoverflow.question.spring.rest.controllers;
  
  import org.springframework.hateoas.Resource;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  public class AbstractController {
  
  
      @RequestMapping(value="/cat", method=RequestMethod.GET)
      public Resource&lt;String&gt; cat() {
          return new Resource&lt;&gt;("cat");
      }
  }
  </code></pre>
  
  <p>Here is my controller which use methodOn :</p>
  
  <pre><code>package com.stackoverflow.question.spring.rest.controllers;
  import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
  import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn;
  
  import org.springframework.hateoas.Resource;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.bind.annotation.RestController;
  
  @RestController
  @RequestMapping(value = "/test", produces = { "application/json; charset=utf-8" })
  public class TestController extends AbstractController {
  
      @RequestMapping(method = RequestMethod.GET)
      public Resource&lt;String&gt; test() {
          return new Resource&lt;&gt;("test", linkTo(
                  methodOn(TestController.class).cat()).withRel("cat"), linkTo(
                  methodOn(TestController.class).uglyfix()).withRel("uglyfix"));
      }
  
      @RequestMapping(value = "/uglyfix", method = RequestMethod.GET)
      public Resource&lt;String&gt; uglyfix() {
          return new Resource&lt;&gt;("ugly fix", linkTo(TestController.class).slash(
                  "cat").withRel("cat"));
      }
  
  }
  </code></pre>
  
  <p>This is what i get when I go to /resources/test :</p>
  
  <pre><code>{
      "content": "test",
      "links": [
          {
              "rel": "cat",
              "href": "http://localhost:8080/resources/cat"
          },
          {
              "rel": "uglyfix",
              "href": "http://localhost:8080/resources/test/uglyfix"
          }
      ]
  }
  </code></pre>
  
  <p>And this is what I would expect to have and what I want hateoas to do :</p>
  
  <pre><code>{
      "content": "test",
      "links": [
          {
              "rel": "cat",
              "href": "http://localhost:8080/resources/test/cat"
          },
          {
              "rel": "uglyfix",
              "href": "http://localhost:8080/resources/test/uglyfix"
          }
      ]
  }
  </code></pre>
  
  <p>Of course, I could do what I did in the endpoint uglyfix but I do not like this solution because it mean that if I change my request mapping in my abstract controller, I will have to change the code of my TestController.</p>
  
  <p>Maybe adding @RequestMapping(value="test") at the top of my abstract controller will fix my problem, but I do not want this solution neither because I want to use my extends my abstract controller with more than one controller.</p>
  
  <p>Is there a clean way to do, what I expect ?</p>