Is there any Spring @Required annotation equivalent in EJB 3.0?
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.
精彩评论