DEV Community

eidher
eidher

Posted on • Edited on

1

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)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up