通过注解方式@EJB注入和JNDI查找方式并使用其他EJB或者服务

 1.通过JNDI查找方式来查找其他的bean
InitialContext ctx = new InitialContext();
HelloWorld helloworld = (HelloWorld) ctx
.lookup("实现类的简单名称/remote");


 2.通过注解@EJB
 例如
 @EJB Other other;//现在就可以使用Other里面的公共方法了,条件是Other必须是一个EJB对像
 @Resource TimeService TimeService;//注入其他的对象,比如EJB3中TimeService类,@Resource类路径是javax.anontation.Resource;

猜你喜欢

转载自javaeedevelop.iteye.com/blog/1830721
EJB