当前位置: 首页 > 知识库问答 >
问题:

使用Arquillian Weld-001408进行集成测试:带有限定符@默认的类型XXXX的不满足依赖项

刘高峯
2023-03-14

我正在用Arquillian创建我的第一个EJB测试,并且我面临着一个似乎很常见的问题,考虑到有很多相同问题的帖子。但在尝试了所有的建议后,我还是找不到一个解决办法。我在一个野兽14号上运行它。

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>
<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>

你知道我做错了什么吗?谢谢

共有1个答案

唐威
2023-03-14

我认为您在部署中缺少beans.xml,因此CDI在归档文件中找不到任何bean,因为未为归档文件启用CDI。

尝试通过以下方法将beans.xml添加到部署中:

archive.addAsResource("META-INF/beans.xml);
 类似资料:
  • 我是Java EE新手。我想测试JSF,因此制作了一个简单的程序,但无法部署它。我收到以下错误消息: 我的代码如下:Customer.java: 注册Controller.java: 为了编译它,我必须包含CDIAPI。jar作为外部库。有人能帮我吗?提前谢谢大家。

  • 在Netbeans上部署到Glassfish时,我遇到了以下错误。这是我第一次尝试CDI。我读了所有关于这个问题的帖子,但毫无帮助。 日志: 我的程序代码: 泰斯特普尔战争 指数xhtml 雇员控制员。JAVA 员工EJB 雇员 桌子 豆。xml 这是我部署时自动生成的源代码 雇员。JAVA 有什么想法吗?

  • 我在JBoss上部署我的Java应用程序时遇到了一个愚蠢的问题。在我使用接口类更改源代码之前,一切都很好。所以这是我的问题: ... 在JBoss 7.1上部署时会出现以下错误: 10:05:34838错误[org.jboss.msc.service.fail](msc服务线程1-6)MSC00001:无法启动服务jboss。部署。单元“mdk-exchange-1.1.0.战争”。WeldSer

  • 在JBoss上部署我的Java应用程序时,我遇到了一个愚蠢的问题。在我使用接口类更改源代码之前,一切都很好。所以我的问题是: 10:05:34,838错误[org.jboss.MSC.service.fail](MSC服务线程1-6)MSC00001:无法启动服务jboss.deployment.unit。“MDK-Exchange-1.1.0.war”。WeldService:org.jboss

  • 我确实遇到了与这里所解释的相同的问题:JBOSS7.1.3:@EJB工作而@Inject失败,这可能是相同的设置(Wildfly 8.0)。 尽管有一个带有producer的资源类,但我不能注入一个Logger实例。Neiter在控制器中,也不在EJB中。“问题1”如果我错了,请纠正我,我应该可以将它们注入@model bean和注有@stateless(EJB)的bean中,不是吗? 下面是我的

  • 我的LdapService类是一个无状态EJB,默认无参数构造函数(此项目是一个EJB包) 我试着把它注入到另一个类中,比如: CDI可以识别带有@EJB注释的bean,但注入点向我抛出了关于@Inject的错误: 如果在LdapService中使用@named(“LdapService”),然后在注入点使用: 然后我得到了这个错误: 部署失败。消息是:org.jboss.weld.excepti