1

How do you define an annotation in Spring that is semantically equivalent to @Bean, but has another name?

(Why? I'm building a DSL in which the functionality would fit, but it would greatly benefit from naming the annotation more closely to the role it plays in the library).

pstobiecki
  • 1,804
  • 1
  • 17
  • 30
  • if it's supposed to be a Bean, what name do you think you can come up to which 'll be closer to the role it plays than Bean does? – Stultuske Aug 29 '18 at 12:44
  • @Stultuske `@MyEnhancedBean`? just sayin... – Eugene Aug 29 '18 at 12:45
  • `@ExportMe`, for instance. Tie up a couple of dependencies together and then export the whole graph (e.g. to JSON), starting from one of them. – pstobiecki Aug 29 '18 at 12:48
  • create your annotation that extends @bean. – Antoniossss Aug 29 '18 at 12:57
  • 1
    @Antoniossss What a useless comment. Either you can help, or you can't. If the latter is the case, please don't spam. – pstobiecki Aug 29 '18 at 13:00
  • Contrary to @Antoniossss suggestion, I don't believe you can extend an annotation. Check out this answer: https://stackoverflow.com/questions/7761513/is-there-something-like-annotation-inheritance-in-java/18585833#18585833 – Cuga Aug 29 '18 at 13:08
  • @Cuga ihh i didnt know that - thought it works like simple interfaces ;) – Antoniossss Aug 29 '18 at 13:09

1 Answers1

2

Well... It was as easy as:

@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Bean
public @interface CustomAnnotation {
}
pstobiecki
  • 1,804
  • 1
  • 17
  • 30