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



我正在尝试运行一个 arquillian 测试,该测试使用映射有 @Singleton 和@Startup注释的 bean,在单例内部有一些缓存 使用@Resource注入的无限西班牙语类型(查找="JNDI"(,错误只告诉无法设置 filds

我确定我在测试类中缺少一些东西,这是来自类和 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>

最新更新