0

Does somebody know how to create a "shortcut" for a couple of annotations in CDI?

You know, something called meta-annotations in Spring world:

@Singleton
@Transactional(value = TxType.REQUIRED, dontRollbackOn = SomeException.class)
@SomeOtherAnnotations
public @interface MyService {
    // ...
}

@MyService
public class OrderService {
  // ...
}

The goal is obvious: just to don't have to specify the same setup in every class. As far as I know, it's not possible in CDI, but does somebody know if EJB 3.2 supports something similar?

halfer
  • 19,824
  • 17
  • 99
  • 186
G. Demecki
  • 10,145
  • 3
  • 58
  • 58

1 Answers1

1

CDI has the concept of stereotypes that you can use in your example:

@Singleton
@Transactional(value = TxType.REQUIRED, dontRollbackOn = SomeException.class)
@SomeOtherAnnotations
@Stereotype
@Target(TYPE)
@Retention(RUNTIME)
public @interface MyService {}
Antonin Stefanutti
  • 1,061
  • 6
  • 6