gpt4 book ai didi

jboss - Arquillian 和 JBoss Wildfly

转载 作者:行者123 更新时间:2023-12-05 01:03:59 30 4
gpt4 key购买 nike

我目前正在尝试使用 jboss wildfly 运行 arquillian 测试,但是在运行它时抛出了 java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy 异常。

我有以下配置:
jboss wildfly-8.1.0.CR1
Derby 10.9.1.0

为了使用 derby networkServer(不是内存),我在 jboss Wildfly 中部署了 derbyclient.jar(名称=derbyclient.jar,运行时名称:derbyclient.jar)

Maven项目结构:

example
example-ear
example-ejb
example-web

Arquillian 测试用例包含在 example-ejb 项目中。

pom(arquillian-container 是 wildfly-arquillian-container-managed-8.0.0.Final):
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>

Arquillian JUnit 测试用例:
...
@RunWith(Arquillian.class)
public class PersonIT {

@Deployment
public static Archive<?> createTestArchive() {
return ShrinkWrap.create(WebArchive.class, "test.war")
.addPackage("example.util")
.addPackage("example.model")
.addPackage("example.model.constraints")
.addPackage("example.model.embeddables")
.addPackage("example.model.enumeration")
.addPackage("example.model.listeners")
.addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
.addAsResource("META-INF/default_mapping.xml", "META-INF/default_mapping.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
// Deploy our test datasource
.addAsWebInfResource("test-ds.xml", "test-ds.xml")
;
}

@PersistenceContext
private EntityManager em;

@Inject
private UserTransaction utx;


@Before
public void preparePersistenceTest() throws Exception {
clearData();
insertData();
startTransaction();
}
...

@After
public void commitTransaction() throws Exception {
utx.commit();
}

@Test
public void test1() throws Exception {
}
}

测试持久性.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="primary" transaction-type="JTA">
<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
<jta-data-source>java:jboss/datasources/npptDS</jta-data-source>
<mapping-file>META-INF/default_mapping.xml</mapping-file>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
<property name="javax.persistence.schema-generation.scripts.action" value="drop-and-create"/>
<property name="javax.persistence.schema-generation.scripts.create-target" value="chapter04Create.ddl"/>
<property name="javax.persistence.schema-generation.scripts.drop-target" value="chapter04Drop.ddl"/>
<property name="javax.persistence.sql-load-script-source" value="import.sql"/>
</properties>
</persistence-unit>
</persistence>

test-ds.xml(包含在 ejb maven 项目中):
<?xml version="1.0" encoding="UTF-8"?>
<datasources xmlns="http://www.jboss.org/ironjacamar/schema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.org/ironjacamar/schema http://docs.jboss.org/ironjacamar/schema/datasources_1_0.xsd">
<datasource jndi-name="java:jboss/datasources/npptDS"
pool-name="npptDS"
enabled="true"
use-java-context="true">
<connection-url>jdbc:derby://localhost:1527/nppt</connection-url>
<driver>derbyclient.jar</driver>
</datasource>
</datasources>

运行 arquillian 测试时出现异常:
07:26:45,536 INFO  [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 11) HHH000400: Using dialect: org.hibernate.dialect.DerbyTenSevenDialect
07:26:45,545 WARN [org.hibernate.dialect.DerbyDialect] (ServerService Thread Pool -- 11) HHH000328: Unable to load/access derby driver class sysinfo to check versions : org.apache.derby.tools.sysinfo from [Module "org.hibernate:main" from local module loader @43a2a89a (finder: local module finder @6beb3926 (roots: D:\05_programme\jboss\wildfly-8.1.0.CR1\modules,D:\05_programme\jboss\wildfly-8.1.0.CR1\modules\system\layers\base))]
07:26:45,604 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 11) MSC000001: Failed to start service jboss.persistenceunit."test.war#primary": org.jboss.msc.service.StartException in service jboss.persistenceunit."test.war#primary": java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172) [wildfly-jpa-8.1.0.CR1.jar:8.1.0.CR1]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.1.0.CR1.jar:8.1.0.CR1]
at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_45]
at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474)
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.1.0.CR1.jar:8.1.0.CR1]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_45]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_45]
at java.lang.Thread.run(Thread.java:744) [rt.jar:1.7.0_45]
at org.jboss.threads.JBossThread.run(JBossThread.java:122)
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
at sun.reflect.annotation.AnnotationParser.parseClassArray(AnnotationParser.java:673) [rt.jar:1.7.0_45]
at sun.reflect.annotation.AnnotationParser.parseArray(AnnotationParser.java:480) [rt.jar:1.7.0_45]
at sun.reflect.annotation.AnnotationParser.parseMemberValue(AnnotationParser.java:306) [rt.jar:1.7.0_45]
at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:241) [rt.jar:1.7.0_45]
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:88) [rt.jar:1.7.0_45]
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70) [rt.jar:1.7.0_45]
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3178) [rt.jar:1.7.0_45]
at java.lang.Class.getAnnotation(Class.java:3137) [rt.jar:1.7.0_45]
at sun.reflect.annotation.AnnotationType.<init>(AnnotationType.java:131) [rt.jar:1.7.0_45]
at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:84) [rt.jar:1.7.0_45]
at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:221) [rt.jar:1.7.0_45]
at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:88) [rt.jar:1.7.0_45]
at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70) [rt.jar:1.7.0_45]
at java.lang.Class.initAnnotationsIfNecessary(Class.java:3178) [rt.jar:1.7.0_45]
at java.lang.Class.getAnnotations(Class.java:3158) [rt.jar:1.7.0_45]
at org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader.getPhysicalAnnotations(JPAOverriddenAnnotationReader.java:2975) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader.initAnnotations(JPAOverriddenAnnotationReader.java:345) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader.isAnnotationPresent(JPAOverriddenAnnotationReader.java:326) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.annotations.common.reflection.java.JavaXAnnotatedElement.isAnnotationPresent(JavaXAnnotatedElement.java:60)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.syncAnnotatedClasses(Configuration.java:3723) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1409) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:850) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:397) [hibernate-core-4.3.5.Final.jar:4.3.5.Final]
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842) [hibernate-entitymanager-4.3.5.Final.jar:4.3.5.Final]
at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44) [jipijapa-hibernate4-3-1.0.1.Final.jar:]
at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.1.0.CR1.jar:8.1.0.CR1]
... 8 more

07:26:45,617 ERROR [org.jboss.as.controller.management-operation] (management-handler-thread - 2) JBAS014613: Operation ("deploy") failed - address: ([("deployment" => "test.war")]) - failure description: {"JBAS014671: Failed services" => {"jboss.persistenceunit.\"test.war#primary\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"test.war#primary\": java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy"}}
07:26:45,619 ERROR [org.jboss.as.server] (management-handler-thread - 2) JBAS015870: Deploy of deployment "test.war" was rolled back with the following failure message:
{"JBAS014671: Failed services" => {"jboss.persistenceunit.\"test.war#primary\"" => "org.jboss.msc.service.StartException in service jboss.persistenceunit.\"test.war#primary\": java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
Caused by: java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy"}}
07:26:45,626 INFO [org.jboss.weld.deployer] (MSC service thread 1-7) JBAS016009: Stopping weld service for deployment test.war
07:26:45,659 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 11) JBAS011410: Stopping Persistence Unit (phase 1 of 2) Service 'test.war#primary'
07:26:45,662 INFO [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010409: Unbound data source [java:jboss/datasources/npptDS]
07:26:45,698 INFO [org.jboss.as.server.deployment] (MSC service thread 1-1) JBAS015877: Stopped deployment test.war (runtime-name: test.war) in 78ms
07:26:45,702 INFO [org.jboss.as.controller] (management-handler-thread - 2) JBAS014774: Service status report
...

提前致谢。

问候, 马克斯

最佳答案

我已经解决了。
问题是微部署中缺少一个包。

@Deployment
public static Archive<?> createTestArchive() {
return ShrinkWrap.create(WebArchive.class, "test.war")
.addPackage("example.util")
.addPackage("example.model")
.addPackage("example.model.constraints")
.addPackage("example.model.embeddables")
.addPackage("example.model.enumeration")
.addPackage("example.model.listeners")
.addPackage("example.model.validator")
.addAsResource("META-INF/test-persistence.xml", "META-INF/persistence.xml")
.addAsResource("META-INF/default_mapping.xml", "META-INF/default_mapping.xml")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
// Deploy our test datasource
.addAsWebInfResource("test-ds.xml", "test-ds.xml")
;
}

异常消息不好。
消息中缺少上下文。
所以也许 hibernate 应该记录当前正在处理的类或其他东西。

org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader
private void initAnnotations() {
if ( annotations == null ) {
XMLContext.Default defaults = xmlContext.getDefault( className );
if ( className != null && propertyName == null ) {
//is a class
Element tree = xmlContext.getXMLTree( className );
Annotation[] annotations = getPhysicalAnnotations();
...
}

关于jboss - Arquillian 和 JBoss Wildfly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24104845/

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