How to use ejb in webapplication
I want to call ejb from servlet via remote interface. Maybe it is a RTFM question but i cannot find solution via Google or documentation. What configuration steps I need to do than ejb be accessible for webapps
I use Jboss 4.2, Java 1.6
Thanks for your开发者_StackOverflow answer!
Place this in your servlet:
@EJB
private YourEJBRemoteInterface remoteService;
And you will have your service injected. (you may need to set the name
of the @EJB
annotation)
Another way is to use JNDI lookup, but this is obsolete.
Update: Since your JBoss version seems obsolete as well, the JNDI lookup is the way to go. int your servlet init(..)
method lookup the EJB through JNDI (using InitialContext
), and set them as fields, as if dependency-injection has been performed.
精彩评论