The annotation javax.ejb.Startup (@Startup) is used to mark an EJB so to make the EJB can be brought up during the application is running up. However, if you have multiple automatic loaded EJBs, then a question comes to you, how to make sure there loading sequence? Now, in EJB 3.1, you may use the annotation javax.ejb.DependsOn (@DependsOn) to achieve this. Please see the following example:

@Singleton
public class PrimaryBean { ... }

SecondaryBean depends on PrimaryBean:

@Singleton
@DependsOn("PrimaryBean")
public class SecondaryBean { ... }

If there is a third been needed to be automatically loaded, and you want the third been will be loaded after PrimaryBean and SecondaryBean have been loaded, so you need to:

@Singleton
@DependsOn("PrimaryBean", "SecondaryBean")
public class ThirdBean { ... }

In the case above, EJBs will be loaded in the order: 1. PrimaryBean; 2. SecondaryBean; 3. ThirdBean. If you just removed the dependence from SecondaryBean, the container will load either PrimaryBean or SecondaryBean firstly, then the ThirdBean.
 
Reference:
1. Initializing Singleton Session Beans (The Java EE 6 Tutorial) https://docs.oracle.com/cd/E19798-01/821-1841/gippq/index.html
posted on 2017-09-26 16:33  Rick Qin  阅读(266)  评论(0编辑  收藏  举报