我正在用Arquillian创建我的第一个EJB测试,并且考虑到有相同问题的大量帖子,我所面临的事情似乎非常普遍。但是,在尝试了所有建议之后,我一直无法找到解决方案。 我正在通过wildfly14运行它。
我的测试班
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.inject.*;
@RunWith(Arquillian.class)
public class LicenseManagerTest {
@Deployment
public static WebArchive createDeployment() {
WebArchive war = ShrinkWrap.create(WebArchive.class)
.addClasses(LicenseManager.class)
.addPackages(true, "package1", "package2");
return war;
}
@Inject
private LicenseManager licenseManager;
@Test
public void getAboutTest() {
Assert.assertNotNull(licenseManager.getAbout().getText());
}
}
EJB管理器
import javax.ejb.Remote;
@Remote
public interface LicenseManager {
AboutDTO getAbout();
}
BEAN类
@Stateless(name = "LicenseManagerEJB3")
@Remote(LicenseManager.class)
public class LicenseManagerBean implements LicenseManager{
@Override
public AboutDTO getAbout(){
*My code goes here*
}
}
Arquillian.xml
<?xml version="1.0"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian
http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<defaultProtocol type="Servlet 3.0"/>
<container qualifier="widlfly-managed" default="true">
<configuration>
<property name="jbossHome">target/wildFly-14.0.1.Final</property>
<!--<property name="managementAddress">127.0.0.1</property>-->
<!-- Port offset allows running the tests while a WildFly server is already running -->
<property name="javaVmArguments">-Djboss.socket.binding.port-offset=10000 -Xms512m -Xmx1024m -XX:MaxPermSize=512m --add-modules java.se</property>
<property name="managementPort">19990</property>
<property name="username">admin</property>
<property name="password">admin</property>
</configuration>
</container>
POM文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>artifactName</artifactId>
<parent>
<groupId>package1</groupId>
<artifactId>artifactName</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../name1/pom.xml</relativePath>
</parent>
<properties>
<version.arquillian>1.4.1.Final</version.arquillian>
<version.wildfly>14.0.1.Final</version.wildfly>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>false</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<!-- Project dependencies -->
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${version.arquillian}</version>
<scope>test</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<version>${version.arquillian}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.core</groupId>
<artifactId>arquillian-core-api</artifactId>
<version>${version.arquillian}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<version>8.2.1.Final</version>
<exclusions>
<exclusion>
<groupId>sun.jdk</groupId>
<artifactId>jconsole</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>wildFlyManaged</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack</id>
<phase>process-test-classes</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-dist</artifactId>
<version>${version.wildfly}</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>target</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
在测试配置期间,可以毫无问题地启动与我的混合依赖关系的多个EJB,但是没有问题,但是没有启动LicenseManagerEJB3,并且在执行测试代码时出现以下错误:
由以下原因引起:org.jboss.weld.exceptions.IllegalArgumentException:WELD-001408:类型为带限定符@Default的LicenseManager的依赖关系不令人满意 在注入点[BackedAnnotatedField] @注入私有package1.LicenseManagerTest.licenseManager 在package1.LicenseManagerTest.licenseManager(LicenseManagerTest.java:0) 在org.jboss.weld.core@3.0.5.Final//org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:83) 在org.jboss.weld.core@3.0.5.Final//org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:70) 在org.jboss.weld.core@3.0.5.Final//org.jboss.weld.manager.BeanManagerImpl.createInjectionTarget(BeanManagerImpl.java:1025) 在org.jboss.weld.core@3.0.5.Final//org.jboss.weld.util.ForwardingBeanManager.createInjectionTarget(ForwardingBeanManager.java:204) 在部署时.0d8da7a8-dc23-4657-ac07-40964685a2c1.war // org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectNonContextualInstance(CDIInjectionEnricher.java:143) 在部署时.0d8da7a8-dc23-4657-ac07-40964685a2c1.war // org.jboss.arquillian.testenricher.cdi.CDIInjectionEnricher.injectClass(CDIInjectionEnricher.java:125) ...另外142个 由以下原因引起:org.jboss.weld.exceptions.DeploymentException:WELD-001408:类型为带限定符@Default的LicenseManager的依赖关系不令人满意 在注入点[BackedAnnotatedField] @注入私有package1.LicenseManagerTest.licenseManager 在package1.LicenseManagerTest.licenseManager(LicenseManagerTest.java:0) 在org.jboss.weld.core@3.0.5.Final//org.jboss.weld.bootstrap.Validator.validateInjectionPointForDeploymentProblems(Validator.java:378) 在org.jboss.weld.core@3.0.5.Final//org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:290) 在org.jboss.weld.core@3.0.5.Final//org.jboss.weld.bootstrap.Validator.validateProducer(Validator.java:425) 在org.jboss.weld.core@3.0.5.Final//org.jboss.weld.injection.producer.InjectionTargetService.validateProducer(InjectionTargetService.java:36) 在org.jboss.weld.core@3.0.5.Final//org.jboss.weld.manager.InjectionTargetFactoryImpl.validate(InjectionTargetFactoryImpl.java:153) 在org.jboss.weld.core@3.0.5.Final//org.jboss.weld.manager.InjectionTargetFactoryImpl.createInjectionTarget(InjectionTargetFactoryImpl.java:81) ...还有147个
您知道我在做什么错吗?谢谢
答案 0 :(得分:0)
我认为您在Deployment中缺少bean.xml,因此CDI在归档文件中找不到任何bean,因为未为归档文件启用CDI。
尝试通过
将bean.xml添加到您的部署中archive.addAsRessource("META-INF/beans.xml);