Reputation: 7877
@Local
public interface EJBA{
// declares a method 'validate'
}
@Stateless
public class EJBABean implements EJBA{
// implements the method 'validate'
}
class Model{
@EJB
private EJBA ejbA;
public void doSomething(){
ejbA.validate();
}
}
Now, if I do the following from the execute method of a Struts 1.2 action class
new Model().validate();
ejbA of Model is null, resulting in a NullPointerException. The question is similar to this but, in my case, I am running the client code (Model) as well as the bean in the JBoss 6.1 Final server itself. The model and the EJB are in the a separate jar file and the the action classes are in a war file. Both of these are packaged inside an ear file.
If I use a context lookup using [ear-name]/EJBABean/local, I am able to access it though. What am I doing wrong ?
Upvotes: 1
Views: 305
Reputation: 4941
Your Model
class is not managed by the container and therefore JBoss is not able to identify ejbA
as an injected EJB. You have to turn your Model
class into an EJB by annotating it with @Stateless
/@Stateful
/@Singleton
.
That's why a JNDI lookup in which the container doesn't take part, works perfectly.
Upvotes: 1