Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7667631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:09:21+00:00 2026-05-31T15:09:21+00:00

I created the following annotation: public @interface NavAnnotation { boolean addToAdminMenu() default false; }

  • 0

I created the following annotation:

public @interface NavAnnotation {

    boolean addToAdminMenu() default false;

}

… then try to annotate a domain class:

@NavAnnotation ( addToAdminMenu = true )
class Information {...}

… and do something with that in a controller:

def appDomainClasses = grailsApplication.domainClasses.findAll {
    it.class.isAnnotationPresent( NavAnnotation )

}
[ appDomainClasses : appDomainClasses ]

… but that annotated class is not getting picked up. Any ideas on what I’m missing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T15:09:23+00:00Added an answer on May 31, 2026 at 3:09 pm

    Couple things…

    1.) Ensure that your annotation has a retention policy of @Retention(RetentionPolicy.RUNTIME). The RUNTIME retention policy allows the annotation to be available for reflection at runtime. So your interface should look like….

    import java.lang.annotation.ElementType;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;
    
    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    public @interface NavAnnotation {
        boolean addToAdminMenu() default false;
    }
    

    2.) grailsApplication.domainClasses returns a DefaultGrailsDomainClass and not the actual class you want to preform reflections on. Instead you want to access the underlining class using the getClazz() method like this….

    def appDomainClasses = grailsApplication.domainClasses.findAll {
        it.getClazz().isAnnotationPresent( NavAnnotation )
    
    }
    

    I’ve tested to confirm that it works. Enjoy!

    -Thanks

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created the following interface: <?php interface Action { public function execute(\requests\Request $request, array
I created the following method for retrieving stored settings from the database: public String
I've created an XML schema by annotating an existing Java domain model class, now
I've got following classes: public class Container { private String name; private Data data;
Let's say I have the following two classes: package example.model; public class Model {
I have the following code: @Name(myService) @Scope(ScopeType.APPLICATION) @Stateless public class MyService { private Service
I have following entity class User: public class User implements Serializable { @Column(length =
Today I wanted to create my first annotation interface following this documentation and I
I created a custom annotation for logging following the example in this blog post
Say I have the following EJB (using ejb3): @Stateless(name=Queries) @Remote(Queries.class) @Local(Queries.class) public final class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.