ejb测试
新建weblogic的domain
默认路径C:\Oracle\Middleware\user_projects\domains
weblogic的destsrc勾上,协商src\meta-inf
version可以不写
测试的时候weblogic11的weblogic.jar不能拷贝出来引用,直接引用weblogic下的路径
测试代码:
package com.test;
import java.util.List;
import java.util.Properties;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import com.demo.interfaces.Hello;
import com.demo.interfaces.HelloHome;
//import weblogic.security.s
//weblogic/security/subject/AbstractSubject
public class teatEjb {
public static void main(String[] args) throws Exception {
InitialContext ctx=getInitialContext();
//查找JNDI名为Hello的EJB组件
Object obj=ctx.lookup(HelloHome.JNDI_NAME);
//获得远程EJB组件的home接口的引用
HelloHome home=(HelloHome)PortableRemoteObject.narrow(obj,HelloHome.class);
//获得远程EJB组件的remote接口的引用
Hello hello=home.create();
List list = hello.returnList();
for(int i=0;i<list.size();i++){
System.out.println(list.get(i).toString());
}
}
private static InitialContext getInitialContext() throws Exception
{
String url = "t3://localhost:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put("java.naming.factory.initial", "weblogic.jndi.WLInitialContextFactory");
properties.put("java.naming.provider.url", url);
if (user != null) {
properties.put("java.naming.security.principal", user);
properties.put("java.naming.security.credentials", (password == null) ? "" : password);
}
return new InitialContext(properties);
}catch (Exception e) {
//throw new JNDIException("can't initial context!", e);
}
return null;
}
}