Debugging CAP Java with VS Code

Configure VS Code to launch or attach to a CAP Java Spring Boot app, set breakpoints in event handlers, and inspect request context at runtime.

Debugging CAP Java with VS Code

The Extension Pack for Java and Spring Boot Extension Pack give you a full Java debugger inside VS Code.

Required extensions

Install both from the VS Code Extensions panel.

Method 1 — Launch from VS Code (easiest)

Create .vscode/launch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "java",
      "name": "CAP Java (Spring Boot)",
      "request": "launch",
      "mainClass": "com.mycompany.Application",
      "projectName": "bookshop-java",
      "args": "",
      "vmArgs": "-Dspring.profiles.active=default"
    }
  ]
}

Press F5 — VS Code compiles and starts the server with the debugger attached.

Method 2 — Attach to mvn spring-boot:run

Step 1 — start Maven with remote debug

mvn spring-boot:run -Dspring-boot.run.jvmArguments="-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005"

Step 2 — add an attach config to launch.json

{
  "type": "java",
  "name": "Attach to CAP Java",
  "request": "attach",
  "hostName": "localhost",
  "port": 5005
}

Run Attach to CAP Java from the Debug panel.

Set a breakpoint in an event handler

Open CatalogServiceHandler.java, click the line gutter:

@Before(event = CqnService.EVENT_READ, entity = Books_.CDS_NAME)
public void beforeReadBooks(CdsReadEventContext context) {
    // ← breakpoint here
    System.out.println("User: " + context.getUserInfo().getName());
}

Send a GET request to http://localhost:8080/catalog/Books — VS Code pauses at the breakpoint.

Inspect the context object

In the VS Code Variables panel when paused you can expand:

Spring Boot Dashboard

After installing the Spring Boot Extension Pack, a Spring Boot Dashboard appears in the left sidebar. It shows:

Click any endpoint to open it directly in the browser.

Sign in for progress tracking & Q&A →