---
title: "Debugging a Spring Boot App in Neovim"
canonical: "https://mnafshin.info/devtools/07-debugging-spring-boot/"
author: "Afshin Amini"
date: 2026-11-29
---
# Debugging a Spring Boot App in Neovim

A debugger stops a running program at a line you choose, so you can look at its variables and run it one step at a time. Neovim talks to debuggers through the Debug Adapter Protocol, the same protocol VS Code uses. The `nvim-dap` plugin is the client, LazyVim's `dap.core` extra adds keys and a UI, and the Java extra plugs in `java-debug-adapter`, which jdtls loads to run and debug Java.

## What the pieces do

- **nvim-dap** starts a debug session, sets breakpoints and sends "step" or "continue" to the adapter.
- **nvim-dap-ui** opens panels for variables, watches, the call stack and breakpoints.
- **java-debug-adapter** is installed by Mason and runs inside jdtls. It starts or connects to the JVM and reports what the program is doing.

## Launch the app under the debugger

Open `CatalogController.java` from module 9 of the companion code and press `<leader>dc`, "run or continue". Because no session is running, a picker lists debug configurations. jdtls creates one for every class with a `main` method, so in the companion repository the list is long. Type `ShopApp` and choose "Launch module-09-catalog: info.mnafshin.springuniverse.shop.ShopApp".

Spring Boot starts and the UI panels open around the code. The app listens on port 8080 as usual.

## Stop only on the request you care about

Put the cursor on the `return` line of the `catalog` method:

```java
@GetMapping("/catalog")
PagedModel<CatalogItem> catalog(Pageable pageable) {
    return new PagedModel<>(repository.findCatalog(pageable));
}
```

[CatalogController.java](https://github.com/mnafshin/springuniverse-code/blob/main/module-09-catalog/src/main/java/info/mnafshin/springuniverse/shop/CatalogController.java)

`<leader>db` toggles a plain breakpoint, which stops on every request. Here we only want the second page, so press `<leader>dB` instead. It asks for a condition, a Java expression evaluated each time the line runs:

```text
Breakpoint condition: pageable.getPageNumber() == 1
```

Now call the endpoint from a terminal. `curl 'localhost:8080/catalog?page=0&size=2'` answers at once with Coffee and Tea; the condition was false. `curl 'localhost:8080/catalog?page=1&size=2'` hangs, and Neovim jumps to the breakpoint line.

## Read the call stack

The Stacks panel shows the thread, `http-nio-8080-exec-4` in our run, and its frames. The top one is `CatalogController.catalog(Pageable)` at line 19, followed by reflection and Spring MVC frames. `<leader>dk` moves up one frame and `<leader>dj` back down. Generated frames that have no source file show a "Source missing" message instead of opening a file. The Scopes panel shows the variables of the selected frame, here `pageable`, a `PageRequest`, and `this`.

## Evaluate and watch expressions

While paused you can run Java against the live objects. Select an expression and press `<leader>de`, or open the REPL with `<leader>dr` and type:

```text
dap> pageable.getOffset()
2
```

Expressions can call methods on beans too: `repository.findCatalog(pageable).getTotalElements()` returned 4. Calling methods runs real code, so a query you evaluate really hits the database.

A watch is an expression the UI re-evaluates every time the program stops. In the Watches panel, enter insert mode, type `pageable.getPageSize() * 10` and press Enter. It shows `int = 20`, and updates on the next stop.

## Step and finish

`<leader>dO` steps over the current line, `<leader>di` steps into a call and `<leader>do` steps out. `<leader>dc` continues to the next breakpoint. Here, stepping over the `return` line left the controller and landed in Spring's `DirectMethodHandleAccessor`, which is expected: the method was done. Continue, and the `curl` that was waiting prints Croissant and Espresso beans. `<leader>dt` ends the session and stops the app.

## Attach to a JVM that is already running

On a server you rarely start the app from an editor. The JVM starts with the JDK's debug agent, JDWP, listening on a port:

```bash
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005 \
  -jar module-09-catalog/target/module-09-catalog-0.1.0-SNAPSHOT.jar
```

`suspend=n` lets the app start without waiting for a debugger, and the JVM prints "Listening for transport dt_socket at address: 5005". With Maven, the same option goes into `-Dspring-boot.run.jvmArguments`.

The attach configuration needs a host, a port and the jdtls project. LazyVim's built-in "Debug (Attach) - Remote" entry failed here with "Main class ... isn't unique in the workspace, please pass in specified projectname", because several modules contain the same class name. A `.vscode/launch.json` entry with `projectName` works:

```json
{ "type": "java", "request": "attach", "name": "Attach to a JVM on localhost:5005",
  "hostName": "localhost", "port": 5005, "projectName": "module-09-catalog" }
```

Pick it with `<leader>dc`. It connected in under a second, and the conditional breakpoint, stack, scopes, watch, REPL and stepping above all worked. To leave without stopping the app, run `:lua require("dap").disconnect({ terminateDebuggee = false })`; the JVM kept serving requests and accepted the next attach.

JDWP has no password, so on a real server bind it to `address=127.0.0.1:5005` and forward the port over SSH with `ssh -L 5005:localhost:5005 user@server`, then attach to `localhost:5005`. We tested this forward on one machine with a local SSH server, not against a remote host.

IntelliJ's attach configuration does the same job; its extras, such as "Reset Frame" and logging breakpoints, have no equivalent here.

## Recap

- `nvim-dap`, `nvim-dap-ui` and `java-debug-adapter` make up the debugger; `dap.core` and the Java extra set them up.
- `<leader>dc` launches a main class such as `ShopApp`, or attaches to a JVM started with `-agentlib:jdwp` (give the config a `projectName`).
- `<leader>db` sets a breakpoint, `<leader>dB` a conditional one such as `pageable.getPageNumber() == 1`.
- The Stacks and Scopes panels show frames and variables; `<leader>dk` and `<leader>dj` move between frames.
- `<leader>de` and the REPL evaluate Java while paused; the Watches panel keeps expressions up to date.

**Series: Neovim as a Java IDE.** Previous: [IntelliJ IDEA features and their Neovim equivalents](/devtools/06-intellij-features-in-neovim/) · Next: [Running Java tests in Neovim](/devtools/08-running-java-tests/)

## Sources

Official documentation and well-known tutorials read while writing this article. The wording here is our own.

- [nvim-dap documentation](https://github.com/mfussenegger/nvim-dap/blob/master/doc/dap.txt)
- [nvim-dap-ui README](https://github.com/rcarriga/nvim-dap-ui)
- [LazyVim: dap.core extra](https://www.lazyvim.org/extras/dap/core)
- [nvim-jdtls: debugger (via nvim-dap)](https://github.com/mfussenegger/nvim-jdtls#debugger-via-nvim-dap)
- [java-debug: launch and attach options](https://github.com/microsoft/vscode-java-debug#options)
- [Oracle: Java Debug Wire Protocol and the jdwp agent options](https://docs.oracle.com/en/java/javase/25/docs/specs/jpda/conninv.html)
- [IntelliJ IDEA: Debug code](https://www.jetbrains.com/help/idea/debugging-code.html)
- [IntelliJ IDEA: Tutorial: Remote debug](https://www.jetbrains.com/help/idea/tutorial-remote-debug.html)
- [Spring Boot Maven plugin: running your application (`jvmArguments`)](https://docs.spring.io/spring-boot/maven-plugin/run.html)
- [Baeldung: Remote Debugging with IntelliJ IDEA](https://www.baeldung.com/intellij-remote-debugging)
- [Lorenzo Bettini: Neovim and Java with LazyVim, part 4: Running programs](https://www.lorenzobettini.it/2025/03/neovim-and-java-with-lazyvim-part-4-running-programs/)
- [Nirmal Ravidas: Setting Up a Full Spring Boot Dev Environment on Linux with Neovim and LazyVim](https://nirmalravidas.hashnode.dev/spring-boot-dev-environment-linux-neovim-lazyvim)
- [Dhruva Sagar: Neovim as a Java IDE](https://dhruvasagar.dev/posts/neovim-java-ide/)
