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;
通过注解方式@EJB注入和JNDI查找方式并使用其他EJB或者服务
最新推荐文章于 2021-06-08 12:56:39 发布