jboss7 jndi mysql_JBOSS 7创建客户端通过JNDI调用 EJB

JBOSS 6,7调用通过JNDI查找EJB的方法和JBOSS5不一样。

JBOSS 5

Properties props = new Properties();

props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory"); //jndi factory

props.setProperty("java.naming.provider.url", "localhost:1099"); //jndi server url

props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming");//jndi finding package

InitialContext ctx = new InitialContext (props);

DBBeanRemote db = (DBBeanRemote) ctx.lookup("DBBean/remote");

JBOSS 6,7

总结:

1. 查找JNDI

final Hashtable jndiProperties = new Hashtable();

jndiProperties.put(Context.URL_PKG_PREFIXES,

"org.jboss.ejb.client.naming");//让JNDI API知道是由谁来管理我们用来查找JNDI 名字的命名空间的。

final Context context = new InitialContext(jndiProperties);

//appName 和 moduleName分别就打包的格式而定

//如果是.ear就是appName,其它的是moduleName(.jar,.war)

final String appName = "";

final String moduleName = "EJBDBTest";

final String distinctName = "";

//实现类名

final String beanName = DB.class.getSimpleName();

System.out.println(beanName);

//接口类名

final String viewClassName = DBRemote.class.getName();

System.out.println(viewClassName);

String jndi = "ejb:" + appName + "/" + moduleName + "/"

+ distinctName + "/" + beanName + "!" + viewClassName;

System.out.println(jndi);

DBRemote db = (DBRemote) context.lookup(jndi);

In AS7, for remote access to EJBs, you use the ejb: namespace with the following syntax:

For stateless beans:

ejb:///!

For stateful beans:

ejb:///!?stateful

2.加入JAR文件

把jboss-client jar加入到项目,在JBOSS_HOME/bin/client/jboss-client-7.1.0.Final.jar 目录下.

3. 创建客户端调环境(告诉客户端应该去哪里,怎么调server的EJB)

在project path 下创建 jboss-ejb-client.properties

endpoint.name=client-endpoint

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default //connection 的名字

remote.connection.default.host=xx.xxx.xxx.xx //IP

remote.connection.default.port = xxxx //port

remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

//JBOSS 用户名密码

remote.connection.default.username=appuser

remote.connection.default.password=apppassword

或者你可以另外命名这个文件的名字,只要加入系统参数里就好,如下

-Djboss.ejb.client.properties.file.path=/home/me/my-client/custom-jboss-ejb-client.properties

你还可以建立不同的连接

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=one, two

remote.connection.one.host=localhost

remote.connection.one.port=6999

remote.connection.one.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

remote.connection.two.host=localhost

remote.connection.two.port=7999

remote.connection.two.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

分享到:

18e900b8666ce6f233d25ec02f95ee59.png

72dd548719f0ace4d5f9bca64e1d7715.png

2012-08-22 17:17

浏览 9928

评论

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值