Java 如何在测试类中查找EJB,但接口在其他maven项目中?
我使用TestNG和JBoss Embedded EJB对一个EJB项目进行测试,我在另一个单独的项目上有我的接口,在我进行测试的项目上实现良好,实体是另一个项目的一部分。 所以我有树项目:Java 如何在测试类中查找EJB,但接口在其他maven项目中?,java,jakarta-ee,jboss,ejb,jndi,Java,Jakarta Ee,Jboss,Ejb,Jndi,我使用TestNG和JBoss Embedded EJB对一个EJB项目进行测试,我在另一个单独的项目上有我的接口,在我进行测试的项目上实现良好,实体是另一个项目的一部分。 所以我有树项目: oap实体 oap接口(包含我的所有接口) oap Impli(包含oap接口项目的所有实现) 所有这些项目都是专业化的 我尝试通过TestNG使用jboss embedded进行测试,但每次在控制台上运行maven test后,我都会出现以下错误: T E S T S -----------------
T E S T S
-------------------------------------------------------
Running TestSuite
WARN 22-01 17:55:41,764 (BeanSchemaBinding.java:init:233) -You should use the 2.0 version of the Microcontainer xml. xmlns='urn:jboss:bean-deployer:2.0'
lookup
UserTransaction: org.jboss.ejb3.embedded.UserTransactionImpl
javax.naming.NameNotFoundException: ejb: not bound
Tests run: 2, Failures: 2, Errors: 0, Skipped: 0, Time elapsed: 2.408 sec <<< FAILURE!
它是如何给我带来这些错误的?请告诉我,我需要帮助,因为我在这个项目中被阻止了。我使用JBoss Arquillian进行单元测试(使用JUnit和TestNG),它工作起来很有魅力。我也试着使用Arquillian,但我没有成功,如果你能看看这里:还不知道?关于Jboss嵌入式ejb?
package com.jboss.embedded.testng;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.jboss.ejb3.embedded.EJB3StandaloneBootstrap;
import org.jboss.ejb3.embedded.EJB3StandaloneDeployer;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import com.jboss.embedded.testng.Impl.PersonFact;
import org.oap-interfaces.mine.locals.IPersonLocal;
import org.oap-interfaces.mine.remotes.IPersonRemote;
public class HelloWorldTest {
private static boolean containerRunning = false;
private EJB3StandaloneDeployer deployer;
Private IPersonRemote iPersonRemote;
private IPersonLocal iPersonLocal;
@BeforeClass
public void init() {
startupEmbeddedContainer();
InitialContext initialContext;
try {
initialContext = new InitialContext();
iPersonLocal = (IPersonLocal) initialContext.lookup("PersonFact/local");
iPersonFactoryRemote = (IPersonRemote) initialContext.lookup("PersonFact/remote");
} catch (NamingException e) {
System.out.println("*** Can't looked up the EJB's ***" + e);
}
}
@Test
public void localTest() {
System.out.println("**** Local find Client by ID => "+ iPersonLocal.findByClient("1").getFirstName() + " "+iPersonLocal.findByClient("1").getLastName());
}
@Test
public void remoteTest() {
System.out.println("**** Remote find Client by ID => "+ iPersonRemote.findByClient("1").getFirstName() + " "+ iPersonLocal.findByClient("1").getLastName());
}
@AfterClass
public void terminate() throws Exception {
deployer.stop();
deployer.destroy();
EJB3StandaloneBootstrap.shutdown();
containerRunning = false;
}
private void startupEmbeddedContainer() {
if (!containerRunning) {
EJB3StandaloneBootstrap.boot(null);
deployer = EJB3StandaloneBootstrap.createDeployer();
deployer.getArchivesByResource().add("META-INF/persistence.xml");
try {
deployer.create();
deployer.start();
} catch (Exception e) {
System.out
.println("*** Deployer can't be created and the persistance.xml can't be added ***" + e);
}
containerRunning = true;
}
}
}