开发者

Is there any Spring @Required annotation equivalent in EJB 3.0?

开发者 https://www.devze.com 2023-02-09 06:31 出处:网络
Is there any equivalent annotation in EJB for @Required (Spring)? I do dependency injection using setters and I want to be sure that resource was injected (almost no probability of NullPointerExceptio

Is there any equivalent annotation in EJB for @Required (Spring)? I do dependency injection using setters and I want to be sure that resource was injected (almost no probability of NullPointerException ;)). In Spring it is easy:

@Required
public void setProperty(Property p) {
 this.property = p;
}

Is there any way to do such a validation in EJB? (Maybe som开发者_如何学Goe other solution than annotatations). Thanks


In ejb injection is done via @EJB and @Resource (as stated above). If the bean for the given (or auto-generated) name doesn't exist you get an error from the container (in many cases this happens at deployment time).

The only way to (maybe) get a nullpointer exception inside a ejb bean is if you try to access an injected object in the default constructor. By spec injection happens after the constructor and before the @PostConstruct lifecycle is called.

0

精彩评论

暂无评论...
验证码 换一张
取 消