3

我正在编写一个 Groovy 脚本来在我们的 CI 过程中启动 WireMock 服务器:

#!/usr/bin/env groovy

@Grapes([
        @Grab(group = 'com.github.tomakehurst', module = 'wiremock', version = '2.5.0')
])
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.common.ConsoleNotifier
import com.github.tomakehurst.wiremock.common.SingleRootFileSource
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.standalone.JsonFileMappingsSource

def wiremock = new WireMockServer(
        WireMockConfiguration.wireMockConfig()
                .dynamicPort()
                .notifier(new ConsoleNotifier(true))
                .disableRequestJournal()
                .mappingSource(new JsonFileMappingsSource(new SingleRootFileSource(new File("mappings"))))
)

wiremock.start()

我有一个简单的映射:

{
    "request": {
        "urlPattern": "/test",
        "method": "GET"
    },
    "response": {
        "status": 200,
        "body": "42"
    }
}

我可以在该部分中看到该映射/__admin

{
    "mappings": [
        {
            "id": "920e232f-ffbf-42b4-b6f2-1aece217c968",
            "request": {
                "urlPattern": "/test",
                "method": "GET"
            },
            "response": {
                "status": 200,
                "body": "42"
            },
            "uuid": "920e232f-ffbf-42b4-b6f2-1aece217c968"
        }
    ],
    "meta": {
        "total": 1
    }
}

但是当我点击那个 URL 时,我得到:

HTTP ERROR: 500

Problem accessing /test. Reason:

java.lang.NoSuchMethodError: javax.servlet.http.HttpServletResponse.getHeader(Ljava/lang/String;)Ljava/lang/String;

武特?

看起来类路径上的 Servlet API 版本是 2.4!但它来自哪里?来自 Groovy 的安装:${GROOVY_HOME}/lib/servlet-api-2.4.jar

我已经从 Groovy's 中删除了该 JAR lib,WireMock 以所需的响应响应了我。

我该如何解决?显然,我无法修改 CI 服务器上的 Groovy 安装。我应该自己写groovy-starter.conf吗?我不喜欢这个主意。

4

0 回答 0