EJB 3.1 @Startup @Singleton sequence

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

转载于:https://www.cnblogs.com/rickqin/p/7597494.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值