1

我被分配到几个月前开发的应用程序,但从未在生产中部署。这是一场与嵌入式 EJB 的战争。目标服务器在 JavaEE 7 (Weblogic 12.2.1) 中,但由于该服务器在我们的基础设施上不可用,因此已在 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>

有些点对我来说听起来很奇怪:

  • 编译器源和目标:1.8
  • javaee-api:7.0(使用 1.8 安全吗??)
  • arquillian-glassfish-embedded-3.1(对于 javaee 7 ??)
  • glassfish-embedded-all : 4.1 (不应该链接到 arquillian-glassfish-embedded 版本吗?)

这听起来很奇怪,但是 Arquillian 测试在这种配置下运行良好,这些点不是这个问题的主要目标。

然后,几周前,在冻结了几个月后,这个项目需要部署到生产环境中。而且这个项目从未在目标版本的 weblogic 上测试或部署在另一个环境中。

事实上,weblogic 12.2.1 在我们的基础架构上仍然不可用,所以我不得不降级项目以在 weblogic 12.1.3 上运行。(编译器源和目标:1.8 / javaee-api:7 / 删除菱形、流、多次捕获、重构 EJB 计时器、使用 @EJB 进行 EJB 注入,因为 @Inject 的奇怪行为、重构 LocaleDate、try 中的 loadResource,...)

我太着急了,没有去维护 IT 的配置。(虽然,单元测试没问题。)该项目已成功部署并在生产中运行良好。

现在,我有一点时间再花在这个项目上,我试着把它弄清楚,但这是一场噩梦,我不明白发生的一切。

我的方法:

  1. 按原样运行。

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.

  1. 将依赖项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.GAParameterNameProvider在验证 API 1.1 中

嗯。我不明白为什么需要 ParameterNameProvider?通过什么方式?通过 JUnit4 ?为什么要针对 Validation 1.1 进行验证?

  1. 将依赖项添加到 validation-api 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 `

我理解它失败了,因为它SynchronizationTypeJava Persistence 2.1JavaEE 6 中不存在。但同样,我的项目中有什么暗示这种需求???在我的依赖树中,我有jboss-javaee-6.0依赖于hibernate-jpa-2.0-api- 如果我相信它的名字 - 是符合 jpa 2.0 的。

噢,我明白。这是因为我对glassfish-embedded-all:4.1不匹配的依赖项有依赖。

  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>

有人可以帮助我吗?

4

0 回答 0