@DependsOn 用于子类

@DependsOn for subclasses

@DependsOn 可用于确保一个 EJB 在另一个 EJB 之前初始化:

@Startup @Singleton
public class SchemaMigration {
    // ...
}

@DependsOn("SchemaMigration")
public class Crud<E extends BaseEntity> {
    // ...
}

我想知道子类是否也隐式继承了这个约束?

@Startup @Singleton
public class Birds extends Crud<Bird> {
    // ...
}

@Startup @Singleton
public class Frogs extends Crud<Frog> {
    // ...
}

我知道普通的 Java 注释不会被继承,但是 Java EE 改变了一些注释的规则。但是我没有找到关于@DependsOn注解的具体信息。

DependsOn 不能确保一个 EJB 在另一个 EJB 之前初始化。

请参考DependsOn Javadoc:

The container ensures that all singleton beans with which a singleton has a DependsOn relationship have been initialized before the singleton's PostConstruct method is called.

这仅适用于使用引用单例的 ejb 名称的单例 EJB 的具体实例。

关于会话 bean 的继承,EJB 规范 (4.9.2.1) 说:

A session bean class is permitted to have superclasses that are themselves session bean classes. However, there are no special rules that apply to the processing of annotations or the deployment descriptor for this case. For the purposes of processing a particular session bean class, all superclass processing is identical regardless of whether the superclasses are themselves session bean classes. In this regard, the use of session bean classes as superclasses merely represents a convenient use of implementation inheritance, but does not have component inheritance semantics.