EJB学习笔记-3-javaclient访问EJB(remote)

首先导入EJB的jar包到java应用中


然后导入JBoss的依赖jar包


然后在java根目录下建立jboss-ejb-client.properties配置文件


endpoint.name=client-endpoint
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
remote.connection.default.username=admin
remote.connection.default.password=*******



javaclient 代码如下:
package com.manfred.ejb.javaclient;

import java.util.Hashtable;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.manfred.ejb.HelloWorldRemote;

public class EJB_01_JavaClient {

	public static void main(String[] args) throws NamingException {
		final Properties jndiProperties = new Properties();
		jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
		final Context context = new InitialContext(jndiProperties);
		final String appName = "";
		// 部署的jar文件的名字
		final String moduleName = "EJB_01";
		final String distinctName = "";
		// 实现类的类名
		final String beanName = "HelloWorldBean";
		// 接口类的全名
		final String viewClassName = HelloWorldRemote.class.getName();

		String lookupStr = "ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!"
				+ viewClassName;
		System.out.println(lookupStr);

		// 实现客户端对EJB的访问
		HelloWorldRemote hwr = (HelloWorldRemote) context.lookup(lookupStr);
		// hwr.sayHello("Manfred");
		String sss = hwr.sayHello("Manfred");
		System.out.println(sss);

	}

}




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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值