Skip to content

Commit

Permalink
Merge pull request #187 from oleg-nenashev/spring-boot-solutions
Browse files Browse the repository at this point in the history
Add WireMock Spring Boot to the Solutions page
  • Loading branch information
oleg-nenashev authored Sep 29, 2023
2 parents 6f5e8fc + a0aeea2 commit 476fcc6
Showing 1 changed file with 45 additions and 2 deletions.
47 changes: 45 additions & 2 deletions _docs/solutions/spring-boot.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,56 @@
---
layout: solution
title: "Using with Spring Boot"
title: "Using WireMock with Spring Boot"
meta_title: Running WireMock with Spring Boot | WireMock
toc_rank: 116
description: The team behind Spring Cloud Contract have created a library to support running WireMock using the “ambient” HTTP server
redirect_from: "/docs/spring-boot.html"
redirect_from:
- "/docs/spring-boot.html"
logo: /images/logos/technology/spring.svg
---

## WireMock Spring Boot

[WireMock Spring Boot](https://github.com/maciejwalkowiak/wiremock-spring-boot)
simplifies testing HTTP clients in Spring Boot & Junit 5 based integration tests.
It includes fully declarative WireMock setup,
supports multiple `WireMockServer` instances,
automatically sets Spring environment properties,
and does not pollute Spring application context with extra beans.

Example:

```java
@SpringBootTest
@EnableWireMock({
@ConfigureWireMock(name = "user-service", property = "user-client.url")
})
class TodoControllerTests {

@InjectWireMock("user-service")
private WireMockServer wiremock;

@Autowired
private Environment env;

@Test
void aTest() {
// returns a URL to WireMockServer instance
env.getProperty("user-client.url");
wiremock.stubFor(stubFor(get("/todolist").willReturn(aResponse()
.withHeader("Content-Type", "application/json")
.withBody("""
[
{ "id": 1, "userId": 1, "title": "my todo" },
]
""")
)));
}
}
```

## Spring Cloud Contract

The team behind Spring Cloud Contract have created a library to support running WireMock using the "ambient" HTTP server.
It also simplifies some aspects of configuration and eliminates some common issues that occur when running Spring Boot and WireMock together.

Expand Down

0 comments on commit 476fcc6

Please sign in to comment.