【问题标题】:Unable to inject dependencies of injected bean with Arquillian无法使用 Arquillian 注入注入 bean 的依赖项
【发布时间】:2012-10-01 23:30:56
【问题描述】:

我正在使用 Arquillian 为我的测试注入依赖项。如果我将 bean 直接注入到我的测试类中,它可以正常工作,但是如果 bean 具有它们自己的依赖项,则必须注入这些依赖项。

例如:FacLptConfiguration bean 被正确导入到我的测试类中,但它没有被注入到 CfdFileCreator bean 中。我将 FacLptConfigurtion 注入测试类只是为了确认注入有效,但这个类的用户是 CfdFileCreator。

@RunWith(Arquillian.class)
public class CfdFileCreatorArquillianTest {


@Deployment
public static WebArchive createDepolyment() {
    return ShrinkWrap.create(WebArchive.class)
            .addClass(FacLptConfiguration.class)
            .addClass(InterimFileCreator.class)
            .addClass(CfdFileCreator.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsWebInfResource(new File("C:/aLearn/FacLpt/web/WEB-INF/env-entries.properties"));
}

public static String TEST_FOLDER = "C:/aLearn/FacLpt/src/test/testdata/pruebas/";

@Inject
private FacLptConfiguration facLptConfiguration;

@Inject
private CfdFileCreator cfdFileCreator;


@Test
public void createCfd() {
    System.out.println("in createCFD");
    cfdFileCreator.createCFDFile();
}

}

这些注入不起作用:

  @Singleton
  public class CfdFileCreator {


  @Inject
  private InterimFileCreator interimFileCreator;
  @Inject
  private FacLptConfiguration facLptConfiguration;

【问题讨论】:

    标签: jboss-arquillian


    【解决方案1】:

    我认为您的问题是 beans.xml 的位置。对于 Web 存档,它应该是 WEB-INF/beans.xml。使用:

    addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))

    另见https://community.jboss.org/thread/175404

    【讨论】:

      猜你喜欢
      • 2014-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-22
      • 1970-01-01
      • 2013-07-22
      • 1970-01-01
      • 2012-08-02
      相关资源
      最近更新 更多