Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Introduction

In this tutorial, we’re going to talk about Chaos Monkey for Spring Boot.

This tool helps us introduce some of the principles of chaos engineering into our Spring Boot web applications by adding latency to our REST endpoints, throwing errors, or even killing an app.

2. Setup

To add Chaos Monkey to our application, we need a single Maven dependency in our project:

<dependency>
    <groupId>de.codecentric</groupId>
    <artifactId>chaos-monkey-spring-boot</artifactId>
    <version>2.0.0</version>
</dependency>

3. Configuration

Once we have the dependency setup in our project, we need to configure and start our chaos.

We can do this in a couple of ways:

  • At application startup, using chaos-monkey spring profile (recommended)
  • Using chaos.monkey.enabled=true property

By starting the application with chaos-monkey spring profile we don’t have to stop and start the application if we want to enable or disable it while our app is running:

java -jar your-app.jar --spring.profiles.active=chaos-monkey

Another useful property is management.endpoint.chaosmonkey.enabled. Setting this property to true will enable the management endpoint for our Chaos Monkey:

http://localhost:8080/chaosmonkey

From this endpoint, we can see our library’s status. Here is the full list of endpoints and their description that will help change configuration, enable or disable Chaos Monkey and other more granular controls.

Using all the available properties, we can have a more fine-grained control over what happens in our generated chaos.

4. How Does It Work

Chaos Monkey consists of Watchers and Assaults. A Watcher is a Spring Boot component. It makes use of Spring AOP to see when a public method is executed in classes annotated with the following Spring annotations:

  • Component
  • Controller
  • RestController
  • Service
  • Repository

Based on the configuration in our app properties file, our public methods will be either assaulted or not, by one of the following:

  • Latency Assault – adds random latency to the request
  • Exception Assault – throws random Runtime Exception
  • AppKiller Assault – um, the app dies

Let’s take a look at how we can configure our watcher and assaults for a more controlled assault.

5. Watcher

By default, Watcher is only enabled for our services. This means that our assaults will be executed only for public methods in our classes annotated with @Service.

But we can easily change that by configuring properties:

chaos.monkey.watcher.controller=false
chaos.monkey.watcher.restController=false
chaos.monkey.watcher.service=true
chaos.monkey.watcher.repository=false
chaos.monkey.watcher.component=false

Keep in mind that once the application started, we cannot dynamically change the watcher using the Chaos Monkey for Spring Boot management port that we talked about earlier.

6. Assaults

Assaults are basically scenarios that we want to test in our application. Let’s take each type of attack and see what it does and how we can configure it.

6.1. Latency Assault

This type of attack adds latency to our calls. This way our application responds slower and we can monitor how it behaves when for example the database responds slower.

We can configure and turn on or of this type of attack using the properties file of our app:

chaos.monkey.assaults.latencyActive=true
chaos.monkey.assaults.latencyRangeStart=3000
chaos.monkey.assaults.latencyRangeEnd=15000

Another way to configure and switch on and off this type of attack is through the management endpoint of Chaos Monkey.

Let’s turn on the latency attack and add a range of latency between two and five seconds:

curl -X POST http://localhost:8080/chaosmonkey/assaults \
-H 'Content-Type: application/json' \
-d \
'
{
	"latencyRangeStart": 2000,
	"latencyRangeEnd": 5000,
	"latencyActive": true,
	"exceptionsActive": false,
	"killApplicationActive": false
}'

6.2. Exception Assault

This tests how well our application can handle exceptions. Based on configuration it will throw a random Runtime Exception once enabled.

We can enable it using a curl call similar to our latency assault:

curl -X POST http://localhost:8080/chaosmonkey/assaults \
-H 'Content-Type: application/json' \
-d \
'
{
	"latencyActive": false,
	"exceptionsActive": true,
	"killApplicationActive": false
}'

6.3. AppKiller Assault

This one, well, our app will die at some random point. We can enable or disable it with a simple curl call like the previous two types of assault:

curl -X POST http://localhost:8080/chaosmonkey/assaults \
-H 'Content-Type: application/json' \
-d \
'
{
	"latencyActive": false,
	"exceptionsActive": false,
	"killApplicationActive": true
}'

7. Conclusion

In this article, we talked about Chaos Monkey for Spring Boot. We’ve seen that it takes some of the principles of chaos engineering and enables us to apply them to a Spring Boot application.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW