我被分配到几个月前开发的应用程序,但从未在生产中部署过。这是一场带有嵌入式EJB的战争。目标服务器在JavaEE 7(Weblogic 12.2.1)中,但由于我们的infra上没有这个服务器,因此在Glassfish-embedded-3.1上使用Arquillian进行了集成测试。
是的我知道,这不符合逻辑,因为Glassfish-3.1符合JavaEE 6标准。而且,该项目是使用一些Java 8功能构建的。 :)
但没问题,集成测试与此配置运行良好。这是这个版本的pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my-company</groupId>
<artifactId>my-project</artifactId>
<version>1.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<log4j.version>2.5</log4j.version>
<cxf.version>3.1.6</cxf.version>
<failOnMissingWebXml>false</failOnMissingWebXml>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.11.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.4</version>
<scope>compile</scope>
</dependency>
<!-- CXF DEPENDENCIES -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-tools-common</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
<exclusions>
<!--
This dependency should be excluded since it generates java.lang.IncompatibleClassChangeError
on org.objectweb.asm.ClassVisitor (side effect between 2 JAR versions)
-->
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- TEST DEPENDENCIES -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.0.CR4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>4.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eu.ingwar.tools</groupId>
<artifactId>arquillian-suite-extension</artifactId>
<version>1.1.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/target/generated-sources/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/MailService.svc.wsdl</wsdl>
<catalog>${basedir}/src/main/resources/wsdl/catalog.xml</catalog>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>my-project</finalName>
</build>
<profiles>
<profile>
<id>integration-tests-glassfish</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
有些观点对我来说很奇怪:
这听起来很奇怪,但Arquillian测试在这种配置下运行良好,这些点不是这个问题的主要目标。
然后,几周前,在被冻结几个月之后,这个项目需要在生产中部署。此项目从未在目标版本的weblogic上的其他环境中进行测试或部署。
事实上,weblogic 12.2.1在我们的基础设施上仍然无法使用,因此我不得不将项目降级为在weblogic 12.1.3上运行。 (编译器源和目标:1.8 / javaee-api:7 /删除钻石,流,多次捕获,重构EJB计时器,使用@EJB注入EJB,因为使用@Inject进行奇怪的行为,重构LocaleDate,尝试使用loadResource,...)
我是如此匆忙,以至于我没有注意维护IT配置。 (虽然单元测试没问题。)该项目已成功部署并在生产中运行良好。
现在,我有一点时间再次花在这个项目上,我试图把IT放在一边,但这是一场噩梦,我不明白所发生的一切。
我的方法:
UT失败:
java.lang.reflect.InvocationTargetException
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/search/SearchTerm`
好的,这是因为依赖于javaee-api 6.0
。
javaee-api
替换为org.jboss.spec:jboss-javaee-6.0:1.0.0.Final
,稍后再替换为版本3.0.3.Final IT失败:
java.lang.NoSuchMethodError: javax.validation.spi.ConfigurationState.getParameterNameProvider()Ljavax/validation/ParameterNameProvider;
at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:367)`
好的,jboss-javaee-6.0
取决于javax.validation:validation-api:jar:1.0.0.GA
,但ParameterNameProvider
位于validation-api 1.1
咦。我不明白为什么需要ParameterNameProvider?通过什么方式?通过JUnit4?为什么验证验证1.1?
javax.validation:validation-api:1.1.0.Final
。失败:
Nov 14, 2016 5:25:58 PM com.sun.enterprise.deployment.archivist.Archivist readAnnotations
SEVERE: javax.persistence.PersistenceContext.synchronization()Ljavax/persistence/SynchronizationType;
Nov 14, 2016 5:25:58 PM org.glassfish.api.ActionReport failure
SEVERE: Exception while deploying the app [7eeab354-b7aa-4559-bb55-b49bb5d33209]
Nov 14, 2016 5:25:58 PM com.sun.enterprise.v3.server.ApplicationLifecycle deploy
SEVERE: Exception during lifecycle processing
java.lang.IllegalStateException: javax.persistence.PersistenceContext.synchronization()Ljavax/persistence/SynchronizationType;. Related annotation information: annotation [@javax.persistence.PersistenceContext(type=TRANSACTION, unitName=, properties=[], name=)] on annotated element [protected javax.persistence.EntityManager `
我理解它失败了,因为SynchronizationType
自Java Persistence 2.1
以来在JavaEE 6中不存在。但同样,在我的项目中需要什么呢?在我的依赖树中,我有jboss-javaee-6.0
取决于hibernate-jpa-2.0-api
- 如果我相信它的名字 - 符合jpa 2.0。
哦,我明白了。这是因为我对glassfish-embedded-all:4.1
的依赖性不匹配。
org.glassfish.main.extras:glassfish-embedded-all:3.1.2.2
仍然失败...... 就在IT的开始,在服务器启动之前,我有这个错误:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.kneip.writtennotice.business.boundary.test.OutgoingMessageIT
Nov 14, 2016 6:04:20 PM org.reflections.Reflections scan
INFO: Reflections took 896 ms to scan 2 urls, producing 33 keys and 222 values
Nov 14, 2016 6:04:27 PM org.hibernate.validator.internal.util.Version <clinit>
INFO: HV000001: Hibernate Validator 4.3.0.Final
Nov 14, 2016 6:04:29 PM org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory processXMLProbeProviders
SEVERE: MNTG0301:Cannot process XML ProbeProvider, xml = META-INF/gfprobe-provider.xml
java.lang.IllegalStateException: Provider already mapped glassfish:javamail:smtp-transport
at org.glassfish.flashlight.impl.core.ProbeProviderRegistry.registerProbeProvider(ProbeProviderRegistry.java:100)
at org.glassfish.flashlight.impl.provider.FlashlightProbeProviderFactory.registerProvider(FlashlightProbeProviderFactory.java:561)
服务器启动,JDBC资源正常,部署开始但失败:
Nov 14, 2016 6:06:23 PM org.glassfish.webservices.WSServletContextListener contextInitialized
WARNING: Deployment failed
java.lang.ExceptionInInitializerError
at com.sun.enterprise.security.webservices.CommonServerSecurityPipe. <init>(CommonServerSecurityPipe.java:94)
at com.sun.enterprise.security.webservices.GFServerPipeCreator.createSecurityPipe(GFServerPipeCreator.java:101)
at com.sun.xml.wss.provider.wsit.SecurityTubeFactory.createTube(SecurityTubeFactory.java:167)
at com.sun.xml.ws.assembler.TubeCreator.createTube(TubeCreator.java:89)
at com.sun.xml.ws.assembler.TubelineAssemblerFactoryImpl$MetroTubelineAssembler.createServer(TubelineAssemblerFactoryImpl.java:179)
at com.sun.xml.ws.server.WSEndpointImpl.<init>(WSEndpointImpl.java:199)
at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:304)
at com.sun.xml.ws.server.EndpointFactory.create(EndpointFactory.java:299)
at com.sun.xml.ws.server.EndpointFactory.createEndpoint(EndpointFactory.java:145)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:569)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:552)
at com.sun.xml.ws.api.server.WSEndpoint.create(WSEndpoint.java:623)
at org.glassfish.webservices.WSServletContextListener.registerEndpoint(WSServletContextListener.java:282)
....
Caused by: java.lang.IllegalStateException: Failed to find AuthConfigFactory : org.jboss.security.auth.message.config.JBossAuthConfigFactory
at javax.security.auth.message.config.AuthConfigFactory.getFactory(AuthConfigFactory.java:171)
at com.sun.enterprise.security.jmac.config.ConfigHelper.<clinit>(ConfigHelper.java:78)
... 134 more
Caused by: java.lang.ClassNotFoundException: org.jboss.security.auth.message.config.JBossAuthConfigFactory
at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1509)
现在......我不知道该怎么做。
现在我的pom是:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myCompany</groupId>
<artifactId>myProject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<!--
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
-->
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<log4j.version>2.5</log4j.version>
<cxf.version>3.1.6</cxf.version>
<failOnMissingWebXml>false</failOnMissingWebXml>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>1.1.11.Final</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>3.0.3.Final</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>${log4j.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.4</version>
<scope>compile</scope>
</dependency>
<!-- CXF DEPENDENCIES -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-tools-common</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
<exclusions>
<!--
This dependency should be excluded since it generates java.lang.IncompatibleClassChangeError
on org.objectweb.asm.ClassVisitor (side effect between 2 JAR versions)
-->
<exclusion>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- TEST DEPENDENCIES -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-glassfish-embedded-3.1</artifactId>
<version>1.0.0.CR4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.glassfish.main.extras</groupId>
<artifactId>glassfish-embedded-all</artifactId>
<version>3.1.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eu.ingwar.tools</groupId>
<artifactId>arquillian-suite-extension</artifactId>
<version>1.1.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<!-- Addeed to test compile in one pass. Not needed by Eclipse -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.9.1</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${basedir}/target/generated-sources/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/wsdl/MailService.svc.wsdl</wsdl>
<catalog>${basedir}/src/main/resources/wsdl/catalog.xml</catalog>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>written-notice</finalName>
</build>
<profiles>
<profile>
<id>integration-tests-glassfish</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
有人能帮助我吗?