我几天前一直试图实施这个设计,并没有成功。 (在继续之前我告诉我已经阅读了这篇文章" How can I inject an EJB from an other application on the same GlassFish Server?"除了glassfish-ejb-jar.xml之外,我尝试了其中的所有内容)
我有2个耳朵申请。 test.ear是我想要测试它的主要应用程序,但我不想在这个项目中添加任何远程接口,所以我创建了另一个包含远程接口并从中注入EJB的.ear(automation.ear) test.ear。所以我的独立应用程序调用自动化应用程序,无法直接访问测试应用程序。
每个应用程序都包含以下模块:实体,ejb,ear(例如自动化应用程序包含:automation-entities,automation-ejb,automation-ear)
这是我的旅程: (我在所有这些尝试之前部署了test.ear) -first try:我将带有ejb类型的test.ejb作为maven依赖项添加到automation-ejb pom.xml中,并在自动化项目的一个bean中注入了test.ear的EJB,并给它一个mappedName;虽然它有效,但我意识到这是一个误报,它实际上并没有用于test.ear的实现。它使用它拥有的副本(因为依赖) - 第二次尝试:我在test.ear的pom.xml中添加了一个插件来为我创建ejb-client(它只包含接口而不是实现)并将此.jar作为依赖项添加到自动化pom.xml中,然后注入ejb给它mapName并试图勉强;好吧它抱怨没找到课! - >无法部署 - 第三次尝试:我在automation.ear中添加了我想要使用的接口的副本(来自test.ear),并删除了自动化的pom.xml中的依赖项。注入EJB并为其赋予mappedName;试图部署,没有运气!仍然无法找到班级 - >无法部署
以下是我的课程: test.ear应用程序
package com.ericsson.test.service;
import javax.ejb.Local;
@Local
public interface TestService1 {
public String TestMethod1();
}
/////////////////////////////////////////////// ///////
package com.ericsson.test.service;
import javax.ejb.Local;
import javax.ejb.Stateless;
@Local(TestService1.class)
@Stateless(name = "TestService1")
public class TestServiceBean1 implements TestService1{
@Override
public String TestMethod1() {
return "Test Method1";
}
}
automation.ear应用程序
@Remote
public interface RemoteInterfaceTest{
public void doSomething();
}
/////////////////////////////////////////////// /////////////////////////
package com.ericsson.test.service;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.ejb.Singleton;
import javax.ejb.Startup;
import javax.naming.InitialContext;
@Singleton
@Startup
public class RemoteInterfaceTestBean implements RemoteInterfaceTest {
@EJB(mappedName = "Test-Server-Local/test-ejb-0.0.1-SNAPSHOT/TestService1/local")
private TestService1 testService1EJB;
@PostConstruct
public void doSomething() {
try {
InitialContext ic = new InitialContext();
TestService1 service1 = (TestService1) ic
.lookup("java:global/Test-Server-Local/test-ejb-0.0.1-SNAPSHOT/TestService1");
System.out.println(service1.TestMethod1());
} catch (Exception e) {
System.out.println(e.getMessage());
System.out.println("OOOOOOPPPPPPSSSSSSSSS ! First try");
}
try {
testService1EJB.TestMethod1();
} catch (Exception e) {
System.out.println("OOOOOOPPPPPPSSSSSSSSS ! Second try");
}
}
}
这是我得到的例外:
SEVERE: Exception while deploying the app [automation-csdp-remote] : Cannot resolve reference Local ejb-ref name=com.ericsson.test.service.RemoteInterfaceTestBean/testService1EJB,Local 3.x interface =com.ericsson.test.service.TestService1,ejb-link=null,lookup=,mappedName=Test-Server-Local/test-ejb-0.0.1-SNAPSHOT/TestService1/local,jndi-name=,refType=Session
我试过玩了1000次,我检查了玻璃鱼,班级在那里,为什么找不到它?任何想法将不胜感激。