我有一个使用Ivy / Ant的Wiremock项目用于依赖/构建。当我从Eclipse中的启动文件运行它时,它成功启动服务器并请求成功。但是,当我将其构建为docker镜像并运行它时,它会立即崩溃。
docker build:
docker build --force-rm -t <REPO_LOCATION>/assignment_form_api_mock:latest -t <REPO_LOCATION>/assignment_form_api_mock:1.0.6 .
docker run:
docker run -d --name form-api-mock -p 10404:8080 <REPO_LOCATION>/assignment_form_api_mock --verbose --extensions="com.gatesbiz.assignmentdispatch.mock.RequestTemplateTransformerGlobal,com.gatesbiz.assignmentdispatch.mock.AdminAreasRequestTransformer,com.gatesbiz.assignmentdispatch.mock.FormsRequestTransformer,com.gatesbiz.assignmentdispatch.mock.VehicleRequestTransformer"
加载扩展名docker时会记录此堆栈跟踪:
2017-08-14 18:05:24.276 Verbose logging enabled
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/type/TypeReference
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader$3.apply(ExtensionLoader.java:75)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader$3.apply(ExtensionLoader.java:71)
at wiremock.com.google.common.collect.Iterators$8.transform(Iterators.java:799)
at wiremock.com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
at wiremock.com.google.common.collect.TransformedIterator.next(TransformedIterator.java:48)
at wiremock.com.google.common.collect.Maps.uniqueIndex(Maps.java:1163)
at wiremock.com.google.common.collect.Maps.uniqueIndex(Maps.java:1140)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader.asMap(ExtensionLoader.java:43)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader.loadExtension(ExtensionLoader.java:32)
at com.github.tomakehurst.wiremock.extension.ExtensionLoader.load(ExtensionLoader.java:39)
at com.github.tomakehurst.wiremock.standalone.CommandLineOptions.extensionsOfType(CommandLineOptions.java:277)
at com.github.tomakehurst.wiremock.core.WireMockApp.<init>(WireMockApp.java:80)
at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:69)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.run(WireMockServerRunner.java:65)
at com.github.tomakehurst.wiremock.standalone.WireMockServerRunner.main(WireMockServerRunner.java:113)
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.core.type.TypeReference
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 17 more
当我在谷歌上搜索时,我看到人们对杰克逊有版本问题:https://github.com/tomakehurst/wiremock/issues/282
因此我使用wiremock-standalone。我也尝试隐式覆盖杰克逊版本,以确保使用相同版本的jackson-annotations,jackson-databind和jackson-core。如果我没有隐式添加依赖项,我会得到相同的错误,但引入的jar是版本:
jackson-annotations-2.1.2.jar
jackson-core-2.1.3.jar
jackson-databind-2.1.3.jar
Ivy Dependencies:
<dependencies>
<dependency org="com.github.tomakehurst" name="wiremock-standalone" rev="2.7.1" conf="compile->default"/>
<dependency org="io.rest-assured" name="rest-assured" rev="3.0.3" conf="test->default"/>
<dependency org="com.gatesbiz.common" name="logback_core" rev="2.0.13" conf="compile->compile;test->test"/>
<dependency org="commons-io" name="commons-io" rev="2.5"/>
<dependency org="com.fasterxml.jackson.core" name="jackson-annotations" rev="2.9.0"/>
<dependency org="com.fasterxml.jackson.core" name="jackson-databind" rev="2.9.0"/>
<dependency org="com.fasterxml.jackson.core" name="jackson-core" rev="2.9.0"/>
</dependencies>
Dockerfile:
FROM rodolpheche/wiremock
ADD src/test/resources /home/wiremock
ADD /bin /var/wiremock/extensions/af-extensions.jar
搬运工-compose.yml
assignment-form-api-mock:
container_name: assignment-form-api-mock
image: <REPO_LOCATION>/assignment-form-api-mock
ports:
- 10404:8080
command: --extensions="com.gatesbiz.assignmentdispatch.mock.RequestTemplateTransformerGlobal,com.gatesbiz.assignmentdispatch.mock.AdminAreasRequestTransformer,com.gatesbiz.assignmentdispatch.mock.FormsRequestTransformer,com.gatesbiz.assignmentdispatch.mock.VehicleRequestTransformer"