Build a Markdown-based Blog with Spring Boot — Part 6

Build a Markdown Blog with Spring Boot — Part 6

Recap

By now, we have a complete blogging system set up. We add Markdown files to the resources/posts directory and our ContextEventListener class, upon a ContextRefreshedEvent, populates the database with the content from new Markdown files. Then, on the client side, when we request for a specific blog post by its ID, the PostController.getPostById method adds the respective post as a model attribute and returns the appropriate view to render.

What now?

We need to host our database in RemoteMySQL, push our repository to GitHub,and then deploy the repository to Heroku. But before that, let’s add some new files to our repository.

Specify the Java Runtime

We need to specify the Java Runtime version to be used for our application. In the root directory of our project, create a new file system.properties and specify the Runtime version as 11.

Specify Java Runtime version

Create a Heroku profile

We used the application.properties file for our development environment; but for deployment to Heroku, we will need a new set of properties. Create a application-heroku.properties file inside the resources directory.

Add new properties file

RemoteMySQL

Now onto our production database, register for an account in RemoteMySQL. After you are a registered user, you can create a new database; after which RemoteMySQL provides you with details about your credentials, including the username, database name, password, port, host, etc. Keep these secure as we need to pass these as Config Vars to our Heroku deployment.

Open phpMyAdmin from the Databases section
Open phpMyAdmin from the Databases section

GitHub

Before proceeding any further, make sure you’ve committed your changes and pushed them to the remote repository.

Heroku

If you’re new to Heroku, first register for an account. Then, from the dashboard, create a new application with New > Create new app.

Create a new Heroku application
Create a new Heroku application
Enable Automatic Deploys
Enable Automatic Deploys
Add config vars to Heroku
Add config vars to Heroku
  • Set the DATASOURCE_USERNAME variable as the username you received from RemoteMySQL.
  • Set the DATASOURCE_PASSWORD variable as the password you received from RemoteMySQL.
  • Set spring_profiles_active variable as heroku

Live deployment

If the build process didn’t end up in an error, you should be able to open the application and see your blog posts live.

Check live deployment
Check live deployment

Adding new blog posts

Too see if the deployment mechanism works, let us create a new Markdown file, 6_After_Deployment_Blog.md, inside the resources/posts directory in our local repository.

Add new Markdown file
Check for update
Check for update

Wrapping up

This concludes the series. We have built a blog application that reads Markdown files and populates the database with its content. Whenever we push a new Markdown file to our GitHub repository, Heroku automatically deploys the changes in our application.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store