gpt4 book ai didi

java - Singleton.START 上的 Arquillian : Getting WFLYEE0117: Field field cannot be set,

转载 作者:行者123 更新时间:2023-12-01 18:51:56 35 4
gpt4 key购买 nike

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

我确信我在测试类中遗漏了一些东西,这是来自类和 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-struct.xml 文件中以访问模块。

这是 src/test/resources/jboss-deployment-struct.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>

关于java - Singleton.START 上的 Arquillian : Getting WFLYEE0117: Field field cannot be set,,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59721803/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com