How to configure Rollbar with Java Spring

Rollbar offers error monitoring integration for Spring apps. This guide will show you how to install and configure Rollbar for Spring. It will also provide examples of how to use the SDK and advanced configurations.


Configure Gradle dependencies

Depending on your project type, add the appropriate dependency for Gradle.

Spring Boot

If you have a Spring Boot 1 or 2 project, add the following to your dependencies:


For Spring Boot 3+, add the following to your dependencies:


Spring Web MVC

For a Spring Web MVC 5.x project, add the following to your dependencies:


For Spring Web MVC 6.x, add the following to your dependencies:


Get your Access Token

Log into your Rollbar account dashboard. Go to Settings, then Project Access Tokens, and copy the post_server_item access token. Make sure to keep this token secure.

Configure the Rollbar Bean

You can create a new RollbarConfig class, such as the one below, and add it to your project for a simple configuration. Make sure to set your ACCESS_TOKEN and add your project package to the @ComponentScan.

public class RollbarConfig {

   * Register a Rollbar bean to configure App with Rollbar.
  public Rollbar rollbar() {
    return new Rollbar(getRollbarConfigs("<ACCESS_TOKEN>"));

  private Config getRollbarConfigs(String accessToken) {

    // Reference ConfigBuilder.java for all the properties you can set for Rollbar
    return RollbarSpringConfigBuilder.withAccessToken(accessToken)


Register a Rollbar bean in the installation section and load com.rollbar.spring components. At this point, any exceptions raised by Spring will be sent to Rollbar. We also offer several methods to track other items at your convenience.

Logging a Specific Message

You can log messages anywhere in your app. For example, to log a debug message:

rollbar.debug("Here is some debug message");

Add Context Information

You can pass user information as context like this:

 HashMap<String,Object> map=new HashMap<String, Object>();
 map.put("User Name","John Doe");
 map.put("Email","[email protected]");

Exception Logging

If you wish to report data from the HttpServletRequest, use the Rollbar error reporting method. For example:

public String buildLogMessage(Exception e, HttpServletRequest req) {             
    System.out.println("Exception : " + e.toString());
    return "MVC exception: " + e.getLocalizedMessage();

You can also report an error to Rollbar with a specific exception block. For example, to log any Exception, add the following:

try {
   String test = null;
} catch(Exception e) {
   rollbar.error(e, "This is a null pointer exception");

Additional Configuration Options

The Rollbar object allows additional configuration. Reference the config object here in our JavaDoc to learn what you can configure.


The examples below demonstrate how to configure the Rollbar Java SDK:

Configure a new Request Provider
Add a RequestProvider to capture request metadata, such as the remote IP:

// Example add a `RequestProvider` to capture metadata about the request
RequestProvider requestProvider = new RequestProvider
                    // To use a header to resolve the source IP address uncomment below line.

return new Rollbar(RollbarSpringConfigBuilder.withAccessToken("ACCESS_TOKEN")
            // Add the custom requestProvider to the Rollbar instance

Setup a proxy

return new Rollbar(RollbarSpringConfigBuilder.withAccessToken("ACCESS_TOKEN")


You can reference the Spring Boot and Spring WebMVC Java Docs here: