【问题标题】:java.lang.IllegalStateException: No Server ALPNProcessors - WireMockjava.lang.IllegalStateException:没有服务器 ALPNProcessors - WireMock
【发布时间】:2020-05-21 06:31:05
【问题描述】:

我正在尝试在我的 maven 项目上运行单元测试(使用 Wiremock)并观察到以下错误。

java.lang.IllegalStateException: No Server ALPNProcessors

我尝试将alpn-boot-8.1.12.v20180117.jar 添加到Xbootclasspath,如下所示

-Xbootclasspath/p:/path/to/alpn-boot-8.1.12.v20180117.jar

并将其放在我项目的.mvn 目录中的jvm.config 文件中,并通过执行ps -ef | grep Xbootclasspath 验证它是否正在设置,但我仍然遇到相同的错误。

它可以在具有 Java 8 u191 且未添加任何 Xbootclasspath 的 Windows 机器上运行,但不能在具有 Java 8 u181 的 Linux 上运行

我还尝试将以下依赖项添加到我的pom.xml

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-alpn-server</artifactId>
    <version>9.4.20.v20190813</version>
    <scope>test</scope>
</dependency>

但还是不行。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M3</version>
                <configuration>
                    <workingDirectory>${real.base.dir}</workingDirectory>
                    <systemProperties>
                        <log4j.configurationFile>${basedir}/src/test/resources/log4j.xml</log4j.configurationFile>
                    </systemProperties>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
                <version>${jacoco.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>prepare-agent</goal>
                        </goals>
                    </execution>
                    <!-- attached to Maven test phase -->
                    <execution>
                        <id>report</id>
                        <phase>test</phase>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.googlecode.addjars-maven-plugin</groupId>
                <artifactId>addjars-maven-plugin</artifactId>
                <version>1.0.5</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>add-jars</goal>
                        </goals>
                        <configuration>
                            <resources>
                                <resource>
                                    <directory>${basedir}/lib</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.version>3.8.1</maven.compiler.version>
        <maven.surefire.version>3.0.0-M3</maven.surefire.version>

        <javax.validation.version>2.0.1.Final</javax.validation.version>
        <syncope.version>2.1.5</syncope.version>
        <resteasy.client.version>4.4.2.Final</resteasy.client.version>
        <jax.rs.version>2.1.1</jax.rs.version>
        <junit.jupiter.version>5.5.2</junit.jupiter.version>

        <jacoco.version>0.8.5</jacoco.version>
        <real.base.dir>${basedir}</real.base.dir>
    </properties>

    <dependencies>

        <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>${javax.validation.version}</version>
        </dependency>

        <dependency>
            <groupId>javax.ws.rs</groupId>
            <artifactId>javax.ws.rs-api</artifactId>
            <version>${jax.rs.version}</version>
        </dependency>

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
            <version>${resteasy.client.version}</version>
        </dependency>

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxb-provider</artifactId>
            <version>${resteasy.client.version}</version>
        </dependency>

        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
            <version>4.4.2.Final</version>
        </dependency>

        <dependency>
            <groupId>org.syncope.identityconnectors</groupId>
            <artifactId>framework</artifactId>
            <version>0.4.3</version>
        </dependency>


        <!-- Start Test dependencies -->
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>${junit.jupiter.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.github.tomakehurst</groupId>
            <artifactId>wiremock-jre8</artifactId>
            <version>2.25.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.mockito</groupId>
            <artifactId>mockito-core</artifactId>
            <version>3.2.4</version>
            <scope>test</scope>
        </dependency>

        <!-- End Test dependencies -->
    </dependencies>

</project>

【问题讨论】:

  • 你能分享你的 pom.xml 并命令你如何运行测试。
  • 路径可能有区分大小写的问题,在linux中需要准确
  • @slesh mvn clean test
  • @user7294900 我在路径上做了一个ll &lt;file_path&gt; 并且路径存在
  • 如果路径是MyPath,而你输入mypath,它将不起作用,因为文件/文件夹区分大小写

标签: java wiremock


【解决方案1】:

以防任何 M1 Mac 用户像我一样偶然发现此页面。


我的问题 -

我的带有wiremock 测试的spring boot 项目可以在我的旧英特尔mac 上运行,但在我转移到我的新M1 Mac 时无法运行。

_ _

我有 2 条错误消息

  • java.lang.IllegalStateException: 没有服务器 ALPNProcessors!
  • 抑制:java.lang.UnsatisfiedLinkError: no conscrypt_openjdk_jni-osx-aarch_64

修复-

我需要一个属性来 test.application

wiremock.server.httpsPort=-1

【讨论】:

  • 谢谢,它为我节省了几个小时!
  • 谢谢!然而,这只是让我前进到 Luna JIT 一些编译器错误......
【解决方案2】:

将wiremock更改为旧版本解决此问题


<dependency>
    <groupId>com.github.tomakehurst</groupId>
    <artifactId>wiremock-jre8</artifactId>
    <version>2.21.0</version>
    <scope>test</scope>
</dependency>
<!-- Needed for the SSLContextFactory$Client class -->
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-util</artifactId>
    <version>9.4.14.v20181114</version>
    <scope>test</scope>
</dependency>

总之,新版jetty会用到alpn模块,而jdk8没有这个模块。 详情请参考https://github.com/jetty-project/jetty-alpn

【讨论】:

  • 您能否解释一下2.21.0 +wiremock-jre8 版本中的哪个技术更改导致了这个问题?
【解决方案3】:

为了避免 No Server ALPNProcessors 使用较新版本的wiremock时出现错误,例如

<dependency>
    <groupId>com.github.tomakehurst</groupId>
    <artifactId>wiremock-jre8</artifactId>
    <version>2.30.1</wiremock.version>
</dependency>
    

您可以尝试以下依赖项。

适用于 JDK 9 及更高版本

<dependency>  
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-alpn-server</artifactId>
    <version>${jetty.version}</version>
</dependency>
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-alpn-java-server</artifactId>
    <version>${jetty.version}</version>
</dependency>

参考:
https://github.com/eclipse/jetty.project/issues/1894 https://www.eclipse.org/jetty/documentation/jetty-9/index.html#alpn-jdk9

对于 JDK 8

<dependency>  
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-alpn-server</artifactId>
    <version>${jetty.version}</version>
</dependency>
<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-alpn-openjdk8-server</artifactId>
    <version>${jetty.version}</version>
</dependency>

参考:
https://github.com/eclipse/jetty.project/issues/1894https://www.eclipse.org/jetty/documentation/jetty-9/index.html#alpn-openjdk8

【讨论】:

    【解决方案4】:

    指定wiremock-jre8-standalone 的版本就可以了。如here 中所述,问题已在版本 2.32.0 中得到解决:

    # Gradle
    testImplementation 'com.github.tomakehurst:wiremock-jre8-standalone:2.32.0'
    
    #Maven
    <dependency>
        <groupId>com.github.tomakehurst</groupId>
        <artifactId>wiremock-jre8-standalone</artifactId>
        <version>2.32.0</version>
        <scope>test</scope>
    </dependency>
    

    【讨论】:

      猜你喜欢
      • 2020-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-22
      • 2016-03-23
      • 1970-01-01
      相关资源
      最近更新 更多