Booting Spring Boot into Heroku

January 17, 2014
spring heroku spring boot deployment

Spring Boot is a new approach from Spring to build web applications. The quote from Spring is that it “takes an opinionated view of building production-ready Spring applications. Spring Boot favors convention over configuration and is designed to get you up and running as quickly as possible.” One of the things I like doing when evaluating a new framework is to ensure that I have an environment to deploy my work. So this post will show you how to get a sample Spring Boot application running on heroku.

To get started, you need a few prerequistes.

  • JDK 1.7
  • Maven 3
  • A Herkou account
  • Heroku command line tools
  • Git
  • An internet connection :)

The very first thing we need to do is create a very simple application that can be deployed.

  1. Firstly, we will create a vanilla maven project with the correct dependencies for Spring Boot setup. Create a new directory (sample-spring-boot) and a pom.xml file inside it. Put the following contents in the file.

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="" xmlns:xsi=""
        <!-- Inherit defaults from Spring Boot -->
        <!-- Add typical dependencies for a web application -->
        <!-- Package as an executable JAR -->
        <!-- Allow access to Spring milestones and snapshots -->
        <!-- (you don't need this if you are using anything after 0.5.0.RELEASE) -->

  2. Create a sample controller under src/main/java/ It should have the following contents.

    import org.springframework.boot.*;
    import org.springframework.boot.autoconfigure.*;
    import org.springframework.stereotype.*;
    import org.springframework.web.bind.annotation.*;
    public class SampleController {
        String home() {
            return "Hello World!";
        public static void main(String[] args) throws Exception {
        	String webPort = System.getenv("PORT");
            if (webPort == null || webPort.isEmpty()) {
                webPort = "8080";
            System.setProperty("server.port", webPort);
  , args);

  3. Let’s start up our application to see if everything we have done to date is functional. Run the following command in a shell.

    $ java -jar target/*.jar

  4. You should be able to now go to the http://localhost:8080 via your web browser or use curl to access it.

    $ curl http://localhost:8080

  5. Now let’s create a Procfile so heorku will know how to start our application. So create a file with the name Procfile and put it in the root of your project. Add the following contents to the file.

    web: java -jar target/*.jar

  6. Create a file that tells heroku to use Java 1.7. It should have the following contents.


  7. Add your project to a git repository.

    $ git init .
    $ git add .
    $ git commit -m 'initial add'

  8. Assuming you have the heroku command line tools installed, create a heroku application via the following command.

    $ heroku create

  9. Now you should be able to deploy by pushing your code to the heroku remote branch.

    $ git push heroku master

  10. If this has worked your application should now be deployed to heroku.

    $ heroku open

  11. I hope this article has shown you the steps required to deploy a Spring Boot application to herkou. The code for this application can be found here.