grailshateoasgrails-2.4

@Resource is creating controller that shadows my own controller


To render JSON+HAL I've added @Resource anotation to my domain:

@Resource(uri = "/rest/book", formats=['hal'])
class Book {
    String title
    String author
}

The problem is that I already have BookController (no scaffolding) and creating ling via gsp tag (<g:createLink controller='book' />) always creates link to /rest/book not to specyfic action in controller (i.e. /book/index). What is also worth knowing when I type localhost:8080/book/index it is showing JSON response not gsp page.

The @Resource somehow cover the book controller and I don't know how to keep both of them working.

PS I'm using Grails 2.4.4


Solution

  • Use namespaces for your controller.

    class BookController {
    
        static namespace = 'namespaceOne'
    
        // …
    }
    

    and then use the namespace to generate links to your BookController.

    <g:link controller="book" namespace="namespaceOne">Click me</g:link>