Arquillian:获取 WFLYEE0117:无法设置 Field 字段,在 Singleton.START

Arquillian: Getting WFLYEE0117: Field field cannot be set, on Singleton.START

我正在尝试 运行 arquillian 测试,该测试使用映射了 @Singleton 和 @Startup 注释的 bean,在单例中有一些来自 infinispan 的缓存类型使用 @Resource(lookup) 注入= "JNDI"), 错误仅说明无法设置字段

我确定我在测试中遗漏了一些东西 class,这是 class 和 bean 中的代码。

@RunWith(Arquillian.class)
public class EJBsBeanTest {

    private static SimpleDateFormat SDF_YYYYMMDD = new SimpleDateFormat("yyyy-MM-dd");

    private Libreta lib;
    private Documento documento;
    private Documento documentoAdmin;
    private Documento documentoRol;

    @Deployment
    public static Archive<?> createTestArchive() {
        File[] files = Maven.resolver().loadPomFromFile("pom.xml")
                .importRuntimeDependencies().resolve().withTransitivity().asFile();
        WebArchive myArchive = ShrinkWrap.create(WebArchive.class, "test.war")
                .addClasses(ConfigurationBean.class,... )
                .addAsLibraries(files)
                .addAsWebInfResource("jboss-deployment-structure.xml", ArchivePaths.create("jboss-deployment-structure.xml"))                
                .addAsManifestResource(EmptyAsset.INSTANCE, ArchivePaths.create("META-INF/beans.xml"));
        return myArchive;
    }
}

............

@Startup
@Singleton
public class ConfigurationBean {


    private static final Logger logger = Logger.getLogger(ConfigurationBean.class.getName());

    private static Properties props;
    private static IOException ioerror;

    public static final String CACHE_RUA_CEIP = "evaluacionRuaCeip";

    @Resource(lookup = "java:jboss/datagrid-infinispan/container/backend-manager/cache/externos-cache")
    private Cache<String, Object> cacheExternos;

    @Resource(lookup = "java:jboss/datagrid-infinispan/container/shiro-container")
    private CacheContainer basicCacheContainer;

    @Resource(lookup = "java:jboss/datagrid-infinispan/container/backend-manager/cache/permisosapp-cache")
    private Cache<String, Object> cachePermisosApp;


    @PostConstruct
    public void init() {
        try {
            props = new Properties();
            props.load(ConfigurationBean.class.getClassLoader().getResourceAsStream("ftp.properties"));

            cachePermisosApp.clear();
            cacheExternos.clear();

        } catch (Exception ex) {
            logger.log(Level.SEVERE, null, ex);
            throw new RuntimeException(ex);
        }
    }

    public Cache<String, Object> getCacheExternos() {
        return cacheExternos;
    }

    public Properties getProps() {
        return props;
    }

    public CacheContainer getBasicCacheContainer() {
        return basicCacheContainer;
    }

    public Cache<String, Object> getCachePermisosApp() {
        return cachePermisosApp;
    }
}

这是错误:

org.jboss.arquillian.container.spi.client.container.DeploymentException: 
Cannot deploy test.war: {"WFLYCTL0062: Composite operation failed and was rolled back. Steps that failed:" => {"Operation step-1" => {"WFLYCTL0080: Failed services" => {"jboss.deployment.unit.\"test.war\".component.ConfigurationBean.START" => "java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
    Caused by: java.lang.IllegalStateException: WFLYEE0042: Failed to construct component instance
    Caused by: javax.ejb.EJBException: java.lang.IllegalArgumentException: WFLYEE0117: Field cacheExternos cannot be set - object of class org.infinispan.cache.impl.EncoderCache loaded by ModuleClassLoader for Module \"org.infinispan.core:ispn-9.4\" version 9.4.3.Final from local module loader @7776ab (finder: local module finder @79179359 (roots: /jboss/modules,/jboss/modules/system/layers/base,/jboss/modules/system/add-ons/ispn)) is not assignable to interface org.infinispan.Cache loaded by ModuleClassLoader for Module \"deployment.test.war\" from Service Module Loader
    Caused by: java.lang.IllegalArgumentException: WFLYEE0117: Field cacheExternos cannot be set - object of class org.infinispan.cache.impl.EncoderCache loaded by ModuleClassLoader for Module \"org.infinispan.core:ispn-9.4\" version 9.4.3.Final from local module loader @7776ab (finder: local module finder @79179359 (roots: /jboss/modules,/jboss/modules/system/layers/base,/jboss/modules/system/add-ons/ispn)) is not assignable to interface org.infinispan.Cache loaded by ModuleClassLoader for Module \"deployment.test.war\" from Service Module Loader"}}}}

最后我找到了答案,应用程序在生成的 .war 中找不到模块 org.infinispan.core:ispn-9.4 所以我将模块添加到 jboss- deployment-structure.xml 文件以访问模块。

这里是src/test/resources/jboss-deployment-structure.xml

<jboss-deployment-structure>
  <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
  <deployment>
      <dependencies>
          <module name="org.infinispan.core" slot="ispn-9.4"/>
      </dependencies>
  </deployment>
</jboss-deployment-structure>