JNDI远程调用EJB会话bean测试类

来源:互联网 发布:第三方软件测试 编辑:程序博客网 时间:2024/05/16 17:09

package com.customer.service;

import java.util.List;
import java.util.Properties;

import javax.naming.InitialContext;

import com.ejb.bean.TalkRemote;
import com.ejb.entity.Student;

public class findJNDI {
 public static Object getTalkService(String jndiName) throws Exception
 {
  Properties props = new Properties();
  props.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
  props.setProperty("java.naming.provider.url", "localhost:1099");
  props.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
  InitialContext ts = new InitialContext(props);
  return ts.lookup(jndiName);
 }
 public static void main(String[] args) throws Exception {
  TalkRemote t tr= null;
  tr = (TalkRemote)findJNDI.getTalkService("Talk/remote");
  List<Student> stu =  tr.findStudentList();
 }
}

如果以上代码运行报错,需要导入jbossall-client.jar包,该包位于client文件夹下。

推荐使用Junit4测试,这样效益更高。

原创粉丝点击