1

In this question shows to get all methods from controller in grails 2. How can I get in grails 3?

Community
  • 1
  • 1
fsi
  • 1,319
  • 1
  • 23
  • 51

1 Answers1

3

It's a bit easier in Grails 3 (and Grails 2 if you only use methods for actions and no closures):

import grails.web.Action

def data = grailsApplication.controllerClasses.collect { controller ->
   [controller: controller.logicalPropertyName,
    controllerName: controller.fullName,
    actions: controller.clazz.methods.findAll { it.getAnnotation(Action) }*.name.sort()]
}
Burt Beckwith
  • 75,342
  • 5
  • 143
  • 156
  • "and Grails 2 if you only use methods for actions and no closures" - I don't think you have to exclude apps which use closures for actions. The code you showed above works for those too because the framework generates the corresponding methods at compile time in Grails 2. – Jeff Scott Brown May 18 '16 at 18:26