LeX*_*XXa 5 java glassfish-embedded
现在有没有人使用Embeddable API获取服务器上下文(使用org.glassfish.embeddable.GlassFish,不是javax.ejb.embeddable.EJBContainer)?如果有一种方法可以从正在运行的Glassfish获得EJBContainer,但我甚至找不到可用于查找的服务列表.
这是一个解决方法 - 我们可以获取 InitialContext 作为外部客户端。有关完整的解释,请检查EJB_FAQ。这样至少可以测试远程 EJB:
因此完整的示例将如下所示:
//Start GF
GlassFishRuntime gfRuntime = GlassFishRuntime.bootstrap();
GlassFish gf = gfRuntime.newGlassFish();
gf.start();
//Deploy application with EJBs
Deployer deployer = gf.getService(Deployer.class);
String deployedApp = deployer.deploy(new File(...), "--force=true");
//Create InitialContext
Properties props = new Properties();
props.setProperty("java.naming.factory.initial",
"com.sun.enterprise.naming.SerialInitContextFactory");
props.setProperty("java.naming.factory.url.pkgs",
"com.sun.enterprise.naming");
props.setProperty("java.naming.factory.state",
"com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
props.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
InitialContext ic = new InitialContext(props);
//Lookup EJBs
ic.lookup(...)
//Stop GF
gf.stop();
gfRuntime.shutdown();
//CORBA stuck thread, have to kill it manually
System.exit(0);
Run Code Online (Sandbox Code Playgroud)
请注意,末尾有一个 System.exit(0) - com.sun.corba.ee.impl.javax.rmi.CORBA.Util.KeepAlive 线程即使在服务器停止阻止 JVM 停止后仍在运行...
| 归档时间: |
|
| 查看次数: |
1642 次 |
| 最近记录: |