Spring Data Rest controllers: behaviour and usage of @BasePathAwareController, @RepositoryRestController, @Controller and @RestController : <p>I'm trying to understand the exact behaviour of the Spring Data Rest Controllers.</p>

<p>I have made a simple implementation to test 4 kinds of annotated controllers: <code>@BasePathAwareController</code>, <code>@RepositoryRestController</code>, <code>@RestController</code>, <code>@Controller</code></p>

<p>The controller has a mapping for an entity "author" in the repository.</p>

<p>This is the controller:</p>

<pre><code>@BasePathAwareController
//@RepositoryRestController
//@RestController
//@Controller
public class MyController {

    @RequestMapping(value="authors/mycontroller/test")
    public void handleRequest(){
        System.out.println("handleRequest of class MyController");
    }

    @RequestMapping(value="/authors/mycontroller/testslash")
    public void handleSlashRequest(){
        System.out.println("handleSlashRequest of class MyController");
    }

    @RequestMapping(value="api/authors/mycontroller/test")
    public void handleApiRequest(){
        System.out.println("handleApiRequest of class MyController");
    }

    @RequestMapping(value="/api/authors/mycontroller/testslash")
    public void handleSlashApiRequest(){
        System.out.println("handleSlashApiRequest of class MyController");
    }

}
</code></pre>

<p>I'm testing 4 methods because I have some doubts about the right mapping to be used.</p>

<p>For every experiment, I use a different controller with the sames mappings, simply decommenting the annotation that I need for that experiment.</p>

<p>I'm calling these two URLS with HTTP GET:</p>

<pre><code>http://localhost:8080/myApp/api/mycontroller/test
http://localhost:8080/myApp/api/mycontroller/testslash
</code></pre>

<p>This is the result that I obtain using <code>@BasePathAwareController</code>:</p>

<pre><code>http://localhost:8080/myApp/api/mycontroller/test
    White page, No errors, No print on console

http://localhost:8080/myApp/api/mycontroller/testslash
    White page, No errors, No print on console
</code></pre>

<p>This is the result using <code>@RepositoryRestController</code>:</p>

<pre><code>http://localhost:8080/myApp/api/mycontroller/test
    White page, No errors, No print on console

http://localhost:8080/myApp/api/mycontroller/testslash
    White page, and this message on the console (only for the first HTTP GET on this url):
    jul 27, 2016 9:23:57 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
    WARNING: No mapping found for HTTP request with URI [/myApp/api/authors/mycontroller/testslash] in DispatcherServlet with name 'rest'
</code></pre>

<p>This is the result if I use <code>@RestController</code>:</p>

<pre><code>http://localhost:8080/myApp/api/mycontroller/test
    White page, in console: "handleRequest of class MyController"

http://localhost:8080/myApp/api/mycontroller/testslash
    White page, in console: "handleSlashRequest of class MyController"
</code></pre>

<p>Finally, this is the result using <code>@Controller</code>:</p>

<pre><code>http://localhost:8080/myApp/api/mycontroller/test
    HTTP STATUS 404, in console: "handleRequest of class MyController"

http://localhost:8080/myApp/api/mycontroller/testslash
    HTTP STATUS 404, in console: "handleSlashRequest of class MyController"

For both urls I have this warning:

jul 27, 2016 9:28:11 AM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI [/myApp/api/authors/mycontroller/authors/mycontroller/test] in DispatcherServlet with name 'rest'
</code></pre>

<p>I don't understand what's going on.</p>

<p>The only annotation that seems to provide the expected result is the <code>@RestController</code>.</p>

<p><code>@Controller</code> apparently seems to work, but I have an HTTP status 404 and there is a message with an inconsistent URL <code>/myApp/api/authors/mycontroller/authors/mycontroller/test</code>, despite there is 
the correct handling message on the console.</p>

<p>The other two annotations (<code>@BasePathAwareController</code> and <code>@RepositoryRestController</code>) don't do nothing.</p>

<p>In summary:</p>

<ul>
<li><code>@BasePathAwareController</code>: doesn't do nothing</li>
<li><code>@RepositoryRestController</code>: doesn't do nothing</li>
<li><code>@Controller</code>: strange behaviour</li>
<li><code>@RestController</code>: works perfectly</li>
</ul>

<p>It would be greatly appreciated any type of clarification about the behaviour and the usage of every kind of @Controller.</p>

<p>Thanks.</p>
