Skip to content
This repository was archived by the owner on Jul 7, 2026. It is now read-only.
This repository was archived by the owner on Jul 7, 2026. It is now read-only.

ClassCastException when used along with wiremock-spring-boot:4.0.8 #2403

Description

@salat-23

Spring cloud version 2025.1.0
When using @AutoConfigureStubRunner from org.springframework.cloud:spring-cloud-starter-contract-stub-runner, if you have org.wiremock.integrations:wiremock-spring-boot:4.0.8 in the classpath, you get this error:

Caused by: java.lang.ClassCastException: class org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsJsonPathHelper cannot be cast to class com.github.jknack.handlebars.Helper (org.springframework.cloud.contract.verifier.builder.handlebars.HandlebarsJsonPathHelper and com.github.jknack.handlebars.Helper are in unnamed module of loader 'app')
	at com.github.tomakehurst.wiremock.extension.responsetemplating.TemplateEngine.addHelpers(TemplateEngine.java:113)
	at com.github.tomakehurst.wiremock.extension.responsetemplating.TemplateEngine.<init>(TemplateEngine.java:77)
	at com.github.tomakehurst.wiremock.extension.Extensions.configureTemplating(Extensions.java:144)
	at com.github.tomakehurst.wiremock.extension.Extensions.load(Extensions.java:113)
	at com.github.tomakehurst.wiremock.core.WireMockApp.<init>(WireMockApp.java:108)
	at com.github.tomakehurst.wiremock.WireMockServer.<init>(WireMockServer.java:68)
	at org.springframework.cloud.contract.stubrunner.provider.wiremock.WireMockHttpServerStub.start(WireMockHttpServerStub.java:138)
	at org.springframework.cloud.contract.stubrunner.StubServer.start(StubServer.java:51)
	at org.springframework.cloud.contract.stubrunner.StubRunnerExecutor.startStubServers(StubRunnerExecutor.java:299)
	at org.springframework.cloud.contract.stubrunner.StubRunnerExecutor.runStubs(StubRunnerExecutor.java:95)
	at org.springframework.cloud.contract.stubrunner.StubRunner.runStubs(StubRunner.java:77)
	at org.springframework.cloud.contract.stubrunner.BatchStubRunner.runStubs(BatchStubRunner.java:47)
	at org.springframework.cloud.contract.stubrunner.spring.StubRunnerConfiguration.batchStubRunner(StubRunnerConfiguration.java:88)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.lambda$instantiate$0(SimpleInstantiationStrategy.java:155)
	... 62 more

As I understand, this happens because com.github.tomakehurst.wiremock.extension.responsetemplating.TemplateEngine is taken from regular wiremock dependency, which expects com.github.jknack.handlebars.Helper, but spring cloud HandlebarsJsonPathHelper uses shaded wiremock.com.github.jknack.handlebars.Helper

For those who encountered the same issue the fix for the time being would be to exclude wiremock from the org.wiremock.integrations:wiremock-spring-boot:4.0.8 like that:

testImplementation("org.wiremock.integrations:wiremock-spring-boot:4.0.8") {
        exclude group: 'org.wiremock', module: 'wiremock'
        exclude group: 'org.wiremock', module: 'wiremock-jetty12'
}

so TemplateEngine is taken from spring cloud's instead.

Sample dependencies:

testImplementation "org.wiremock.integrations:wiremock-spring-boot:4.0.8"
testImplementation "org.springframework.cloud:spring-cloud-starter-contract-stub-runner"

Sample class:

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, classes = ExampleApplication.class)
@AutoConfigureWebMvc
@AutoConfigureJsonTesters
@AutoConfigureStubRunner(ids = "com.example:rest-api:+:stubs:8099")
@ActiveProfiles("TEST")
class RestApiContractTest { }

Activity

  1. marcingrzejszczak commented on Jan 15, 2026

    @marcingrzejszczak
    Contributor

    The maintainers of WireMock Spring Boot created a wiremock-spring-boot-standalone dependency so we should document that usage. Anybody cares to file a PR?

  2. marcingrzejszczak commented on Jan 15, 2026

    @marcingrzejszczak
    Contributor

    Actually there is a way to solve this - use a wiremock-spring-boot-standalone. We need to document this!

  3. marcingrzejszczak commented on Jan 26, 2026

    @marcingrzejszczak
    Contributor

    So the way to go is to use

    <dependency>
        <groupId>org.wiremock.integrations</groupId>
        <artifactId>wiremock-spring-boot-standalone</artifactId>
        <version>4.0.9</version>
    </dependency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions