Page 2 of 2 FirstFirst 12
Results 11 to 13 of 13

Thread: Creating a controller level annotation that will check request attributes for objects

  1. #11

    Default

    Now that worked for the method level, but failed when I added the annotation at the controller level.

    My code:

    Code:
                HandlerMethod handlerMethod = (HandlerMethod) handler;
    
                if (handlerMethod != null) {
                    //Object bean = handlerMethod.getBean();
                    Method method = handlerMethod.getMethod();
                    if (method != null) {
                        AuthenticationRequired authenticationRequiredAnnotation = AnnotationUtils.findAnnotation(method, AuthenticationRequired.class);
                        if (authenticationRequiredAnnotation != null) {
                            requiresAuthentication = true;
                        }
                    }
                }

  2. #12
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    My bad... I was under the impression that that method also scanned class level but as it turnsout it scans interfaces. So you need to do both I'm afraid. First check the method, if annotation still null check the class (your initial findAnnotation call) ...
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #13
    Join Date
    Sep 2012
    Location
    Australia
    Posts
    2

    Default

    It seems that this will work of this annotation codes and I am happy that you have given this thread to us. I will try this to see if my source will work.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •