Getting started with Spring Boot, Travis and Heroku

Felippe Rodrigo Puhle
3 min readAug 28, 2016

--

First of all, we must start our application with Spring Boot. You can use this app to generate the maven project. Select Web, DevTools, and Test dependencies and then click in the Generate Project button. Import the project into your IDE, and let’s start to code!

We’ll use JSP and JSTL to render a simple “Hello world” view. So, we must import these dependencies to the project. Open the pom.xml file, and add the following lines:

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>

We have to create a class that declares that our application is a Spring Boot application. We’ll use the @SpringBootApplication annotation:

And then, create a configuration class to resolve the view configuration:

We can start to code our logic right now. Let’s create the controller:

The template:

And then, the view:

Alright! You can commit and push the project to GitHub.

Travis-CI

Travis CI is a continuous integration service used to build and test software projects. It will be “listening” our commits on GitHub, and make all the deploy process for us. You can sign in with your GitHub account, as the image bellow shows:

Once logged in, click in the + button(beside “My repositories” text), sync your account and enable the repository of our project.

Now, we’ll have to instruct Travis how to build our project. These instructions will be in the .travis.yml file, in the root path.

language: java
jdk:
- oraclejdk8

Well done! Commit and push the file to the GitHub repository, and see the magic happens.

Heroku

Heroku is a PaaS cloud computing service that supports several programming languages.

First of all, let’s create an account:

And then create an app:

That’s it!

We must teach Heroku how to deploy our app correctly too. For this, create a new file with name Procfile in the root path of our project:

web: java $JAVA_OPTS -Dserver.port=$PORT -jar target/*.jar -Dspring.profiles.active=prod

Teaching Travis CI to deploy the project on Heroku

The first thing to do is copy your Heroku API Key in your account settings:

After this, go to your repository settings in Travis CI and add a new variable with name “HEROKU_API_KEY”:

Now, it’s time to add some configuration lines into our .travis.yml:

language: java
jdk:
- oraclejdk8
deploy:
provider: heroku
api-key:
secure: $HEROKU_API_KEY
app: lippep-spring-boot-test

Commit and push our modified files to GitHub, don’t forgetting to change the name of the app to your application name in Heroku.

Test your application clicking in the Open app button into Heroku dashboard, you must see our “hello world” message.

That’s all folks! You can find the source code here.

Thanks, hope to see you soon!!!

--

--