【问题标题】:Does EJB 3.2 / CDI have an equivalent of Spring 4 Meta annotations?EJB 3.2 / CDI 是否具有等效于 Spring 4 元注释的功能?
【发布时间】:2015-07-01 07:50:06
【问题描述】:

有人知道如何为 CDI 中的几个注释创建“快捷方式”吗?

你知道,在 Spring 世界中称为 meta-annotations 的东西:

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

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

目标很明显:只是不必在每个类中指定相同的设置。据我所知,这在 CDI 中是不可能的,但是有人知道 EJB 3.2 是否支持类似的东西吗?

【问题讨论】:

    标签: java cdi java-ee-7 weld


    【解决方案1】:

    CDI 具有您可以在示例中使用的 stereotypes 概念:

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

    【讨论】:

    • 这正是我想要的。谢谢!
    猜你喜欢
    • 2019-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-10
    • 2012-03-22
    • 2014-10-02
    • 2020-07-21
    • 1970-01-01
    相关资源
    最近更新 更多