使用 TomEE 的 Application Composer 调用 JUnit 测试会抛出 RuntimeException: unable to load properties from jar: /.../jbossts-properties.xml
Calling JUnit test with TomEE's Application Composer throws RuntimeException: unable to load properties from jar: /.../jbossts-properties.xml
我有这个简单的服务class:
@ApplicationScoped
@Transactional
public class MyService {
public String myTransactionalMethod(){
return "hello";
}
}
通过这个简单的测试class:
@RunWithApplicationComposer
@Classes(cdi = true, value = MyService.class)
class MyServiceTest {
@Inject MyService myService;
@Test
void myTransactionalMethod() {
Assertions.assertDoesNotThrow(() ->myService.myTransactionalMethod());
}
}
但是,当我尝试 运行 时,我得到了这个错误:
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: unable to load properties from jar:file:/home/antonio/.m2/repository/org/jboss/narayana/jta/narayana-jta/5.11.2.Final/narayana-jta-5.11.2.Final.jar!/jbossts-properties.xml
at com.arjuna.common.internal.util.propertyservice.BeanPopulator.getNamedInstance(BeanPopulator.java:90)
at com.arjuna.common.internal.util.propertyservice.BeanPopulator.getDefaultInstance(BeanPopulator.java:53)
at com.arjuna.ats.jta.cdi.NarayanaTransactionManager.lambda$new[=13=](NarayanaTransactionManager.java:150)
at com.arjuna.ats.jta.cdi.NarayanaTransactionManager.getDelegate(NarayanaTransactionManager.java:240)
at com.arjuna.ats.jta.cdi.NarayanaTransactionManager.<init>(NarayanaTransactionManager.java:178)
at com.arjuna.ats.jta.cdi.NarayanaTransactionManager.<init>(NarayanaTransactionManager.java:150)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.apache.webbeans.inject.InjectableConstructor.doInjection(InjectableConstructor.java:72)
at org.apache.webbeans.portable.InjectionTargetImpl.newInstance(InjectionTargetImpl.java:201)
at org.apache.webbeans.portable.InjectionTargetImpl.produce(InjectionTargetImpl.java:184)
at org.apache.webbeans.portable.AbstractProducer.produce(AbstractProducer.java:134)
at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:124)
at org.apache.webbeans.component.ManagedBean.create(ManagedBean.java:66)
at org.apache.webbeans.context.creational.BeanInstanceBag.create(BeanInstanceBag.java:76)
at org.apache.webbeans.context.AbstractContext.getInstance(AbstractContext.java:159)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:125)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:101)
at org.apache.webbeans.intercept.ApplicationScopedBeanInterceptorHandler.getContextualInstance(ApplicationScopedBeanInterceptorHandler.java:65)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.get(NormalScopedBeanInterceptorHandler.java:71)
at com.arjuna.ats.jta.cdi.NarayanaTransactionManager$$OwbNormalScopeProxy0.getTransaction(com/arjuna/ats/jta/cdi/NarayanaTransactionManager.java)
at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorBase.intercept(TransactionalInterceptorBase.java:83)
at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorRequired.intercept(TransactionalInterceptorRequired.java:47)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.webbeans.component.InterceptorBean.intercept(InterceptorBean.java:136)
at org.apache.webbeans.intercept.InterceptorInvocationContext.proceed(InterceptorInvocationContext.java:65)
可能是什么原因?为什么它甚至首先提到 Narayana?我不应该使用 Apache Geronimo 吗?此外,这应该是一个单元测试,因此我无论如何都应该忽略所有事务装饰。
这是我正在使用的:
- Java11
- TomEE 8.0.8
- 休眠 5.6.2.Final
这是pom.xml
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<junit.version>5.8.2</junit.version>
<mockito.version>4.2.0</mockito.version>
<tomee.version>8.0.8</tomee.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.6.2.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>8.0.1</version>
<scope>provided</scope>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>ch.vorburger.mariaDB4j</groupId>
<artifactId>mariaDB4j</artifactId>
<version>2.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>rocks.limburg.cdimock</groupId>
<artifactId>cdimock</artifactId>
<version>1.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-testing</artifactId>
<version>5.6.2.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>openejb-junit5</artifactId>
<version>${tomee.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>openejb-mockito</artifactId>
<version>${tomee.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>shareboard</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<warName>${artifactId}</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<disableXmlReport>true</disableXmlReport>
<useFile>false</useFile>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
</configuration>
</plugin>
</plugins>
</reporting>
此外,整个 TomEE8.0.8/lib
文件夹包含在 classpath
Application Composer 不应读取任何外部配置文件,因此它们不应该成为问题。
可能是什么原因?这种测试以前有效。 class路径中的某些内容肯定已更改,但我真的无法解释可能已更改的内容。
我通过删除 hibernate-testing
依赖项解决了这个问题。不幸的是,我没有任何技术解释
我有这个简单的服务class:
@ApplicationScoped
@Transactional
public class MyService {
public String myTransactionalMethod(){
return "hello";
}
}
通过这个简单的测试class:
@RunWithApplicationComposer
@Classes(cdi = true, value = MyService.class)
class MyServiceTest {
@Inject MyService myService;
@Test
void myTransactionalMethod() {
Assertions.assertDoesNotThrow(() ->myService.myTransactionalMethod());
}
}
但是,当我尝试 运行 时,我得到了这个错误:
Caused by: java.lang.RuntimeException: java.lang.RuntimeException: unable to load properties from jar:file:/home/antonio/.m2/repository/org/jboss/narayana/jta/narayana-jta/5.11.2.Final/narayana-jta-5.11.2.Final.jar!/jbossts-properties.xml
at com.arjuna.common.internal.util.propertyservice.BeanPopulator.getNamedInstance(BeanPopulator.java:90)
at com.arjuna.common.internal.util.propertyservice.BeanPopulator.getDefaultInstance(BeanPopulator.java:53)
at com.arjuna.ats.jta.cdi.NarayanaTransactionManager.lambda$new[=13=](NarayanaTransactionManager.java:150)
at com.arjuna.ats.jta.cdi.NarayanaTransactionManager.getDelegate(NarayanaTransactionManager.java:240)
at com.arjuna.ats.jta.cdi.NarayanaTransactionManager.<init>(NarayanaTransactionManager.java:178)
at com.arjuna.ats.jta.cdi.NarayanaTransactionManager.<init>(NarayanaTransactionManager.java:150)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.apache.webbeans.inject.InjectableConstructor.doInjection(InjectableConstructor.java:72)
at org.apache.webbeans.portable.InjectionTargetImpl.newInstance(InjectionTargetImpl.java:201)
at org.apache.webbeans.portable.InjectionTargetImpl.produce(InjectionTargetImpl.java:184)
at org.apache.webbeans.portable.AbstractProducer.produce(AbstractProducer.java:134)
at org.apache.webbeans.component.AbstractOwbBean.create(AbstractOwbBean.java:124)
at org.apache.webbeans.component.ManagedBean.create(ManagedBean.java:66)
at org.apache.webbeans.context.creational.BeanInstanceBag.create(BeanInstanceBag.java:76)
at org.apache.webbeans.context.AbstractContext.getInstance(AbstractContext.java:159)
at org.apache.webbeans.context.AbstractContext.get(AbstractContext.java:125)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.getContextualInstance(NormalScopedBeanInterceptorHandler.java:101)
at org.apache.webbeans.intercept.ApplicationScopedBeanInterceptorHandler.getContextualInstance(ApplicationScopedBeanInterceptorHandler.java:65)
at org.apache.webbeans.intercept.NormalScopedBeanInterceptorHandler.get(NormalScopedBeanInterceptorHandler.java:71)
at com.arjuna.ats.jta.cdi.NarayanaTransactionManager$$OwbNormalScopeProxy0.getTransaction(com/arjuna/ats/jta/cdi/NarayanaTransactionManager.java)
at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorBase.intercept(TransactionalInterceptorBase.java:83)
at com.arjuna.ats.jta.cdi.transactional.TransactionalInterceptorRequired.intercept(TransactionalInterceptorRequired.java:47)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.apache.webbeans.component.InterceptorBean.intercept(InterceptorBean.java:136)
at org.apache.webbeans.intercept.InterceptorInvocationContext.proceed(InterceptorInvocationContext.java:65)
可能是什么原因?为什么它甚至首先提到 Narayana?我不应该使用 Apache Geronimo 吗?此外,这应该是一个单元测试,因此我无论如何都应该忽略所有事务装饰。
这是我正在使用的:
- Java11
- TomEE 8.0.8
- 休眠 5.6.2.Final
这是pom.xml
<properties>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
<junit.version>5.8.2</junit.version>
<mockito.version>4.2.0</mockito.version>
<tomee.version>8.0.8</tomee.version>
</properties>
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.6.2.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>
<dependency>
<groupId>org.apache.bval</groupId>
<artifactId>bval-jsr</artifactId>
<version>2.0.5</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>8.0.1</version>
<scope>provided</scope>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>ch.vorburger.mariaDB4j</groupId>
<artifactId>mariaDB4j</artifactId>
<version>2.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>rocks.limburg.cdimock</groupId>
<artifactId>cdimock</artifactId>
<version>1.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-testing</artifactId>
<version>5.6.2.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>openejb-junit5</artifactId>
<version>${tomee.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>openejb-mockito</artifactId>
<version>${tomee.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>shareboard</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.3.0</version>
<configuration>
<warName>${artifactId}</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<disableXmlReport>true</disableXmlReport>
<useFile>false</useFile>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.5</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<configLocation>google_checks.xml</configLocation>
</configuration>
</plugin>
</plugins>
</reporting>
此外,整个 TomEE8.0.8/lib
文件夹包含在 classpath
Application Composer 不应读取任何外部配置文件,因此它们不应该成为问题。
可能是什么原因?这种测试以前有效。 class路径中的某些内容肯定已更改,但我真的无法解释可能已更改的内容。
我通过删除 hibernate-testing
依赖项解决了这个问题。不幸的是,我没有任何技术解释