[JAVA] NoHttpResponseException in Spring Boot + WireMock


Fixed the Spring Boot App that is running commercially. There is a place in the App that uses RestTemplate to call the REST API of other linked systems, and unit tests including that part were carried out by setting up a mock server with WireMock.

When I added a test according to the renovation, the existing test suddenly NoHttpResponseException:[server] failed to respond I started to moss with exceptions.

It seems that it is not a mistake of the test itself because it is in a state where it passes when the test is executed alone and it is moss when it is executed through. So the investigation started.


It seems to be a bug that occurs when HttpURLConnection is used for the Http Client of the app that accesses WireMock.

https://github.com/tomakehurst/wiremock/issues/97 This is applicable because Rest Template of Spring also uses HttpURLConnection internally.


Use spring-cloud-contract-wiremock.

https://github.com/tomakehurst/wiremock/issues/97 The issue shows several types of countermeasures, so it seems that you should adopt the one you like. The selection criteria are as follows.

As the name suggests, spring-cloud-contract-wiremock uses wireMock internally, so changes to the test code were minimal. Specifically, just change the notation of the server settings and specify the directory of the existing test resource. See Official for detailed usage.


public class ExampleUnitTest {
    public WireMockRule wireMockRule = new WireMockRule(8080);


@AutoConfigureWireMock(port = 8080, stubs = "classpath*:/META-INF/**/mappings/**/*.json")
public class ExampleUnitTest {

As mentioned above, in my case, the existing test code can be passed as it is just by changing the path of the test resource specified by stubs =.

Recommended Posts

NoHttpResponseException in Spring Boot + WireMock
Set context-param in Spring Boot
Spring Boot 2 multi-project in Gradle
Major changes in Spring Boot 1.5
Spring Boot application development in Eclipse
Write test code in Spring Boot
Implement REST API in Spring Boot
What is @Autowired in Spring boot?
Thymeleaf usage notes in Spring Boot
Build Spring Boot + Docker image in Gradle
Static file access priority in Spring boot
Output Spring Boot log in json format
Local file download memorandum in Spring Boot
Challenge Spring Boot
Create Java Spring Boot project in IntelliJ
Loosen Thymeleaf syntax checking in Spring Boot
[Practice! ] Display Hello World in Spring Boot
Use DynamoDB query method in Spring Boot
Spring Boot Form
Spring Boot Memorandum
gae + spring boot
DI SessionScope Bean in Spring Boot 2 Filter
Change session timeout time in Spring Boot
SameSite cookie in Spring Boot (Spring Web MVC + Tomcat)
Run a Spring Boot project in VS Code
Output request and response log in Spring Boot
Use Servlet filter in Spring Boot [Spring Boot 1.x, 2.x compatible]
How to add a classpath in Spring Boot
Java tips-Create a Spring Boot project in Gradle
How to bind to property file in Spring Boot
Annotations used in Spring Boot task management tool
View the Gradle task in the Spring Boot project
SPRING BOOT learning record 01
Spring Boot + Heroku Postgres
Spring boot memo writing (1)
First Spring Boot (DI)
SPRING BOOT learning record 02
Spring Boot2 cheat sheet
Spring Boot exception handling
Spring Boot Servlet mapping
Spring boot development-development environment-
Spring Boot learning procedure
Use Interceptor in Spring
Learning Spring Boot [Beginning]
Microservices in Spring Cloud
Spring Boot 2.2 Document Summary
[Spring Boot] DataSourceProperties $ DataSourceBeanCreationException
Spring Boot 2.3 Application Availability
Spring boot tutorials Topics
Get cookies in Spring
Download with Spring Boot
Specify the encoding of static resources in Spring Boot
Include external jar in package with Spring boot2 + Maven3
I checked asynchronous execution of queries in Spring Boot 1.5.9
How to create a Spring Boot project in IntelliJ
SSO with GitHub OAuth in Spring Boot 1.5.x environment
How to use CommandLineRunner in Spring Batch of Spring Boot
Test field-injected class in Spring boot test without using Spring container
Until you start development with Spring Boot in eclipse 1
Try gRPC in Spring Boot & Spring Cloud project (Mac OS)
Introduce swagger-ui to REST API implemented in Spring Boot