Reputation: 644
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?
Upvotes: 0
Views: 200
Reputation:
Transforming the comment in answer, the difference can be clarified by printing the class of the controller:
In the first case, the bean class is a proxy:custom.package.CustomController$$EnhancerByCGLIB$$a131be82
you can notice that by the "EnhacerByCGLIB" part. In the second one the class is correct.
Upvotes: 1