In my grails project some of controllers' actions annotated with custom annotation, say CustomAnnotation. Also, there is a filter that checks controllers' actions whether they annotated by CustomAnnotation or not.
I've tried two ways to perform this check:
1) Look for annotations of bean's class methods
def artefact = grailsApplication.getArtefactByLogicalPropertyName("Controller", controllerName)
def controller = applicationContext.getBean(artefact.clazz.name)
def actionMethod = controller.class.declaredMethods.find { it.name == actionName }
def isAnnotated = actionMethod.isAnnotationPresent(CustomAnnotation)
2) Look for annotations of artifact's clazz methods
def artefact = grailsApplication.getArtefactByLogicalPropertyName("Controller", controllerName)
def actionMethod = artefact.clazz.declaredMethods.find { it.name == actionName }
def isAnnotated = actionMethod.isAnnotationPresent(CustomAnnotation)
While the first way doesn't work for me, the second works well. Why these classes are different and what is the difference?
controller.getClass().name? - user800014applicationContexttograilsApplication.mainContext. Example. - dmahapatro