DEV Community

eidher
eidher

Posted on • Updated on

Stereotype and Meta Annotations in Spring

@ComponentScan checks not only for components but for annotations that are themselves annotated with @Component too. Those are stereotype annotations:

  • Component
  • Controller
  • Repository
  • Service

We could add @Configuration and @RestController because @Configuration is annotated with @Component and @RestController is annotated with @Controller (some people disagree)

Meta-annotations are annotations that can be used to annotate other annotations. For example, the next custom annotation @MyTransactionalService is a meta-annotation:

@MyTransactionalService
public class TransferServiceImpl implements TransferService {
  ...
}

@Retention(RUNTIME)
@Target(TYPE)
@Service
@Transactional(timeout=60)
public @interface MyTransactionalService {
  String value() default "";
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)