Search code examples
grailsspring-securityannotationsclosuresgrails-plugin

Difference between two action signatures in grails


In grails we can define an action using 2 ways:-

def actionname()
{

}

and

def actionname = {

}

What is the difference between the two styles? When I tried to insert a spring security annotation above the action (second style) it said "@Secured" not applicable to field. What does this mean? Is it because of closure?


Solution

  • The Grails reference docs 7.The Web Layer mentions the use of closures for controller actions in earlier versions of Grails, the preference is now to use methods. However, both are supported. It goes on to list some benefits of using methods instead.

    Personally, I use methods in all my controllers and have also come across the issue with annotations such as @Secured that only work on methods and not the closures.