在Ejb3会话bean中调用其他Ejb3会话bean
2010-08-17 19:03
357 查看
SayMeRemote
SayMeBean
Client
补充:这个例子中ejb实现类调的类(HelloWordRemote )是在“用ejb3.0做的HelloWord!”这篇文章那个中的ejb。
其实就是在这里ejb中分别用两种不同的形式去调其他ejb中的一个方法,而那个方法return一个String。就这样,so easy!!!
package test2.sessionbean.dao; import javax.naming.NamingException; public interface SayMeRemote { public String sayMe() throws NamingException; public String sayMe2() throws NamingException; }
SayMeBean
package test2.sessionbean.impl; import javax.ejb.EJB; import javax.ejb.Remote; import javax.ejb.Stateless; import javax.naming.InitialContext; import javax.naming.NamingException; import test1.sessionbean.dao.HelloWordRemote; import test2.sessionbean.dao.SayMeRemote; //@Stateless(name = "SayMeBean") 可以修改jndi的名称 @Stateless(name = "SayMeBean") @Remote(SayMeRemote.class) public class SayMeBean implements SayMeRemote { // 在Ejb中调用其他的Ejb // 方法1:使用jndi查找 public String sayMe() throws NamingException { InitialContext ctx = new InitialContext(); HelloWordRemote helloWordRemote = (HelloWordRemote) ctx.lookup("HelloWordBean/remote"); String str = helloWordRemote.sayHello("张胜鸿"); return str; } // 方法2:使用Ejb注入 // @EJB 直接这样就可以,但是在实际中可以能有多个实现。 // 所以这样@EJB(beanName = "HelloWordBean") 可以具体指定。 @EJB(beanName = "HelloWordBean") private HelloWordRemote helloWordRemote; public String sayMe2() throws NamingException { return helloWordRemote.sayHello("张胜鸿2"); } }
Client
package test2.sessionbean.client; import javax.naming.InitialContext; import javax.naming.NamingException; import test2.sessionbean.dao.SayMeRemote; public class Client { public static void main(String[] args) throws NamingException { InitialContext ctx = new InitialContext(); SayMeRemote sayMeRemote = (SayMeRemote) ctx.lookup("SayMeBean/remote"); System.out.println(sayMeRemote.sayMe()); System.out.println(sayMeRemote.sayMe2()); } }
补充:这个例子中ejb实现类调的类(HelloWordRemote )是在“用ejb3.0做的HelloWord!”这篇文章那个中的ejb。
其实就是在这里ejb中分别用两种不同的形式去调其他ejb中的一个方法,而那个方法return一个String。就这样,so easy!!!
相关文章推荐
- JSP调用无状态会话Bean——预定模块_book_success.jsp
- JBoss下的EJB3开发无状态会话Bean
- SpringBoot学习(2)-SpringBoot中其他普通类调用Spring管理的Service、dao等bean
- Weblogic10 + EJB3入门教程(1):编写第一个无状态会话Bean(Stateless Session Bean)
- 会话bean调用实体bean(同一工程目录下)
- win2k环境下基于JBOSS的J2EE开发实践----之三、有状态会话 Bean的开发及多种调用有状态会话Bean方法的实现
- JavaEE Tutorials (7) - 在会话bean中使用异步方法调用
- Weblogic10 + EJB3入门教程(1):编写第一个无状态会话Bean(Stateless Session Bean)
- JBoss下的EJB3开发无状态会话Bean
- EJB3~无状态会话bean
- EJB3.0 无状态会话bean的编写,及客户端调用
- JSP调用无状态会话Bean——预定模块_book0.jsp
- 远程调用其他系统bean报EJBCLIENT000037: Could not load ejb proxy class com.tgb.itoo.basic.service.xxBean的错误
- JSP调用无状态会话Bean——预定模块_book_success0.jsp
- JSP调用无状态会话Bean——预定模块_book_success1.jsp
- 【EJB】Developing EJB Applications -- Chapter5(调用会话Bean)
- EJB3会话Bean的开发——NetBeans和SunJavaSystemApplicationServer
- 无状态会话bean(3)---远程业务接口(未排版)
- 遇到的问题-----------定义一个全局变量,在page_load里赋值,但在其他按钮中调用仍为空
- 【干货篇】调用其他系统http接口超时了,如何处理,方案汇总