Skip to content

Spring Boot 4 wiremock-spring-boot support for spock-spring #2295

@dlehammer

Description

@dlehammer

Describe the bug

Spring has removed @AutoConfigureWireMock support in Spring Cloud 2025.1.0, the Spring Boot 4.0 compatible edition.
@AutoConfigureWireMock previously encapsulated the WireMock setup, transparently supporting utilizing the instance as-is in specs.

Going forward Spring recommends wiremock-spring-boot, unfortunately the replacement @EnableWireMock doesn't work out-of-the-box in Spock 2.4.
Note @EnableWireMock works as advertised in a similar JUnit test.

To Reproduce

I've created a reproducer: https://github.com/dlehammer/spock-wiremock-spring-boot-support-issue that contains the Spring Boot 3.5 starting point and the Spring Boot 4.0 symptom.

The reproducer contains BasicUsageSpec.groovy that demonstrates the symptom and BasicUsageTests.java that demonstrates the JUnit support.

Expected behavior

  • Workaround can be omitted.
  • @InjectWireMock populates the spec field.

Actual behavior

Without the workaround BasicUsageSpec WireMock.stubFor(.. setup fails with

org.apache.hc.client5.http.HttpHostConnectException: Connect to http://localhost:8080 failed: Connection refused
	at java.base@21.0.8/sun.nio.ch.Net.pollConnectNow(Net.java:682)
	at java.base@21.0.8/sun.nio.ch.NioSocketImpl.timedFinishConnect(NioSocketImpl.java:542)
	at java.base@21.0.8/sun.nio.ch.NioSocketImpl.connect(NioSocketImpl.java:592)
	at java.base@21.0.8/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:327)
	at java.base@21.0.8/java.net.Socket.connect(Socket.java:751)
	at app//org.apache.hc.client5.http.impl.io.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:215)
	at app//org.apache.hc.client5.http.impl.io.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:497)
	at app//org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:164)
	at app//org.apache.hc.client5.http.impl.classic.InternalExecRuntime.connectEndpoint(InternalExecRuntime.java:174)
	at app//org.apache.hc.client5.http.impl.classic.ConnectExec.execute(ConnectExec.java:144)
	at app//org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51)
	at app//org.apache.hc.client5.http.impl.classic.ProtocolExec.execute(ProtocolExec.java:195)
	at app//org.apache.hc.client5.http.impl.classic.ExecChainElement.execute(ExecChainElement.java:51)
	at app//org.apache.hc.client5.http.impl.classic.InternalHttpClient.doExecute(InternalHttpClient.java:185)
	at app//org.apache.hc.client5.http.impl.classic.CloseableHttpClient.execute(CloseableHttpClient.java:123)
	at app//com.github.tomakehurst.wiremock.client.HttpAdminClient.safelyExecuteRequest(HttpAdminClient.java:569)
	at app//com.github.tomakehurst.wiremock.client.HttpAdminClient.executeRequest(HttpAdminClient.java:534)
	at app//com.github.tomakehurst.wiremock.client.HttpAdminClient.executeRequest(HttpAdminClient.java:515)
	at app//com.github.tomakehurst.wiremock.client.HttpAdminClient.addStubMapping(HttpAdminClient.java:173)
	at app//com.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:496)
	at app//com.github.tomakehurst.wiremock.client.WireMock.register(WireMock.java:491)
	at app//com.github.tomakehurst.wiremock.client.WireMock.givenThat(WireMock.java:134)
	at app//com.github.tomakehurst.wiremock.client.WireMock.stubFor(WireMock.java:138)
	at reproducer.BasicUsageSpec.returns_a_ping(BasicUsageSpec.groovy:34)

With workaround enabled BasicUsageSpec fails with

Condition not satisfied:

wireMockServer
|
null

	at reproducer.BasicUsageSpec.returns_a_ping(BasicUsageSpec.groovy:47)

Java version

$ java -version
openjdk version "21.0.8" 2025-07-15 LTS
OpenJDK Runtime Environment Temurin-21.0.8+9 (build 21.0.8+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.8+9 (build 21.0.8+9-LTS, mixed mode, sharing)

Buildtool version

$ ./gradlew --version

------------------------------------------------------------
Gradle 9.2.1
------------------------------------------------------------

Build time:    2025-11-17 13:40:48 UTC
Revision:      30ecdc708db275e8f8769ea0620f6dd919a58f76

Kotlin:        2.2.20
Groovy:        4.0.28
Ant:           Apache Ant(TM) version 1.10.15 compiled on August 25 2024
Launcher JVM:  21.0.8 (Eclipse Adoptium 21.0.8+9-LTS)
Daemon JVM:    /home/dlehammer/.sdkman/candidates/java/21.0.8-tem (no JDK specified, using current Java home)
OS:            Linux 6.8.0-90-generic amd64

What operating system are you using

Linux

Dependencies

See reproducer build.gradle for details.

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions