首页 技术 正文
技术 2022年11月7日
0 收藏 648 点赞 710 浏览 1898 个字

1.使用软件

IDE:Eclipse4.3(开普勒) EE版本

服务器:jboss EAP 6.2

eclipse-jboss plugin:jbosstools-Update-4.1.2.Final_2014-03-18_15-46-19-B706

2.服务端开发步骤

  创建EJB项目——创建EJB sessionBean接口(具体先创建的是stateless sessionBean,接口上添加注解@Remote)——实现此接口(添加注解@Stateless,@LocalBean),LocalBean与RemoteBean的区别,statefulSessionBean与statelessSessionBean的区别今后再学习。部署到Jboss上,服务器端的工作完成了

3.客户端调用EJB

  新建普通Java项目,导入EJB3的库,以及外部jar包C:\jboss-eap-6.2\bin\client\jboss-client.jar——拷贝第2步写的远程接口到本项目中,创建 jboss-ejb-client.properties文件,文件内容为

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.host=localhost
remote.connection.default.port=4447
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

文件必须置于classpath根目录下(注意,放子包中不行)——通过JNDI调用,JNDI的name格式为

statelessbean格式  ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>

statefulbean格式    ejb:<app-name>/<module-name>/<distinct-name>/<bean-name>!<fully-qualified-classname-of-the-remote-interface>?stateful

注意<module-name>为部署的项目的名字

部分代码:

Hashtable<String, String> jndiProperties = new Hashtable<String, String>();

jndiProperties.put(Context.URL_PKG_PREFIXES, “org.jboss.ejb.client.naming”);

try {    

Context context = new InitialContext(jndiProperties);

final String appName = “”;
final String moduleName = “myejbservertwo”;//部署的EJB项目的名字
final String distinctName = “”;

String interfaceName = HelloWorldRemote.class.getName();
String implBeanName = “HelloWorld”;
String before_name = “ejb:” + appName + “/” + moduleName + “/” + distinctName + “/”;
String name = before_name+implBeanName+”!”+interfaceName;
HelloWorldRemote hwr = (HelloWorldRemote)context.lookup(name);
String say = hwr.sayHello(“yhuso”);

System.out.println(say);

4.EJB一般分为以下三种:

SessionBean——为客户端服务,通过EntityBean访问DB,可以有状态,也可无状态

EntityBean——用来实现ORM,可以被分配,序列化,可通过网络传输

MessageDrivenBean(消息驱动Bean)——基于JMS消息,可看成异步无状态的SessionBean

5.SLSB(无状态会话Bean是EJB最有价值的部分之一)与门面设计模式Facade

下一篇: JavaScript总结01
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,817
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,899