问题描述
我尝试将Arquillian解决方案集成到我的maven EJB项目中,该项目包含我在其他单独项目中使用的EJB.
I try to integrate the arquillian solution into my maven EJB project which contains juste the EJBs which I uses in other separate projects.
我使用Jboss EAP6.
I use Jboss EAP6.
所以我做到了以下几点:
So i have make it as the following :
我将arquillian.xml制作为ejbModule/src/test/resources/:
I made the arquillian.xml into ejbModule/src/test/resources/:
<container qualifier="jboss" default="true">
<configuration>
<property name="jbossHome">D:\jbdevstudio\jboss-eap-6.2</property>
</configuration>
</container>
在我的项目的pom中,我添加了以下依赖项:
in the pom of my project i added the following dependencies:
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-jbossas-embedded-6</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-junit</artifactId>
<version>1.0.0.Alpha5</version>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
</dependency>
<profiles>
<profile>
<id>jbossas-embedded-6</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>arq-jbossas-managed</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-containermanaged</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<id>arq-jbossas-remote</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-containerremote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>
测试类:
import javax.inject.Inject;
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.oap.subscription.AbstractSubscription;
@RunWith(Arquillian.class)
public class SubscriptionFactoryTest {
@Inject
private SubscriptionFactory subscriptionFactory;
@Deployment
public static JavaArchive getDeployement() {
System.out.println("### testSayHelloEJB");
return ShrinkWrap.create(JavaArchive.class, "subscriptionFactory.jar")
.addClasses(AbstractSubscription.class,SubscriptionFactory.class);
}
@Test
public void getSubscriptionByIdTest() {
System.out.println("### testSayHelloEJB");
}
}
EJB类:
@Remote(ISubscriptionFactoryRemote.class)
@Local(ISubscriptionFactoryLocal.class)
@Stateless
public class SubscriptionFactory extends AbstractSubscription implements ISubscriptionFactoryRemote {
@Override
public AbstractSubscription getSubscriptionById(final Integer id) {
AbstractSubscription ret = null;
if (id != null) {
// create query
final StringBuilder queryString = new StringBuilder("select c from AbstractSubscription c ");
try {
queryString.append("where c.id = :id");
// create query
Query query = this.getEntityManager().createQuery(queryString.toString());
// set parameter
query = query.setParameter("id", id);
// recovers refCountry
ret = (AbstractSubscription) query.getSingleResult();
} catch (final Exception exc) {
}
}
return ret;
}
}
当我将类测试作为Junit测试运行时,它给了我错误:
When i run the class test as Junit test , it gives me the errors :
janv. 20, 2015 12:15:34 PM org.jboss.arquillian.impl.client.container.ContainerRegistryCreator getActivatedConfiguration
Infos: Could not read active container configuration: null
失败轨迹:
java.lang.NoClassDefFoundError: Lorg/jboss/embedded/api/server/JBossASEmbeddedServer;
at java.lang.Class.getDeclaredFields0(Native Method)
at java.lang.Class.privateGetDeclaredFields(Class.java:2397)
at java.lang.Class.getDeclaredFields(Class.java:1806)
at org.jboss.arquillian.impl.core.Reflections.getFieldInjectionPoints(Reflections.java:74)
... 79 more
任何想法.
推荐答案
您使用的Arquillian版本非常旧,我至少会使用1.1.0.Final版本.我也不认为您需要定义的一些Arquillian依赖项.
You're using a very old version of Arquillian, I'd use at least version 1.1.0.Final. I also don't think you need a few of the Arquillian dependencies you have defined.
删除arquillian-jbossas-embedded-6
和arquillian-junit
依赖关系.
关于如何将Arquillian与JBoss EAP结合使用的 quickstart 示例很多.看看那里的一些pom,因为它可能会有所帮助.
There are plenty of quickstart examples of how to use Arquillian with JBoss EAP. Have a look at some of the pom's there as it might help.
这篇关于为什么Arquillian给我:无法读取活动容器配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!