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 along with advanced configurations.


Configure Gradle dependencies

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

Spring Boot

If you have a Spring Boot project add the following to your dependencies


Spring Web MVC

For a Spring Web MVC project 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

For a very simple configuration you can create a new RollbarConfig class such as the one below and add it to your project. 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)


In the installation section, we registered a Rollbar bean and loaded the com.rollbar.spring components. At this point any exceptions raised by Spring will be handled by Rollbar. We also offer several methods to track other items at your convenience.

Logging a Specific Message

You can log your own 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, you may do so using the Rollbar error reporting methods. 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 for additional configs. Reference the config object here in our JavaDoc to learn what you can configure.


Here are some examples which demonstrate how to add the configuration into the Rollbar object.

Configure a new Request Provider
Add a RequestProvider to capture metadata about the request, 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

Configure a proxy with Rollbar

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


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