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 6723849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:37:05+00:00 2026-05-26T09:37:05+00:00

I have seen few examples where customized annotations were used. example @SimpleAnnotation class SampleBean

  • 0

I have seen few examples where customized annotations were used. example

@SimpleAnnotation
class SampleBean {
  @SimpleAnnotation
  public String getName() {
    return "AAA";
  }

  public void setName(String name) {
  }

  public int getHeight() {
    return 201;
  }
}

@Target( { ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@interface SimpleAnnotation {
}

Can anyone tell why we use this?

  • 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-26T09:37:06+00:00Added an answer on May 26, 2026 at 9:37 am

    Spring supports for many Annotation the concept of “meta-annotation”. (I am not sure if it is for all.)

    This mean that you can build your own annotation and annotate the annotation with one of springs “core” annotations.

    For example:

    @Target({ ElementType.FIELD, ElementType.PARAMETER, ElementType.TYPE })
    @Retention(RetentionPolicy.RUNTIME)
    @Service
    public @interface MyService {
    
    }
    

    Then you can use this annotation instead of @Service. (Btw: @Service, @Repository, @Controller use the same technique to “inherit” from @Component)


    One example that make heavy use of this is “inherit” from @Qualifier.
    For an example and some explanation have a look at Spring Reference Chapter: 3.9.3 Fine-tuning annotation-based autowiring with qualifiers (The Example with @Genre is at the end of the chapter.)

    One very usefull construct that can be done with that technique is, that it enables you to combine several Annotations to a (in your use case) more meaning full. So instead of writing at every class of some type allways the same two annotations, for example: @Service and @Qualifiyer("someting") (the org.springframework.beans.factory.annotation.Qualifier). You can create your custom annotation that is annotated with this two annotations, and then use in your beans only this one custom annotation. (@See Avoid Spring Annotation Code Smell Use Spring 3 Custom Annotations)

    If you want to see how powerfull this technique can be use, you can have a look at Context and Dependency Injection Framework.


    Question from the comment:

    The @interface also has some variables defined inside it, what does that signify?

    The Annotations (defined by @Interface) work a bit like beans. This Fields are the properties that can/must be define if you use the annotations. The values can be later on be read via reflection API.

    For example the @Controller Annotation in Spring:

    @Target({ElementType.TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    @Documented
    @Component
    public @interface Controller {
       String value() default "";
    }
    

    The field with name value is that field that can be used without explicit name it: (@Controller("myUrl") is the same @Controller(value="myUrl"))

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

Sidebar

Related Questions

I've seen in a few iPhone examples that attributes have used an underscore _
I have seen a few examples of how to create RSS feeds using ASP.NET
Hi I have seen a few examples of adding breakpoints in gdb using the
I've seen a few examples on here to this problem, but none have solved
I have seen a few examples where the architecture is that there is java
I have seen a few examples where the viewModel (in Silverlight apps) is in
I have seen a few examples lately where if statements are written as follows:
I have seen a few code examples of 1.0 / 1.1 but since a
I have come across Tuples in net 4.0. I have seen few example on
I have seen this in a few .htaccess examples RewriteBase / It appears to

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.