Spring Boot Cloud Deployment
In this tutorial, we are going to deploy the spring-boot application on cloud environment. Application development usually undergoes in three phases which are development, testing and production deployment. We are going to deploy the application on Heroku cloud.
Cloud Registration for Hosting our Service
We need to register on Heroku which provides managed cloud services: Register/Login followed by logging in to use heroku services.
Deploying Spring Boot Application on Cloud
Heroku offers services for different deployments on the cloud, we need Git (Install GIT on your local machine) and Heroku CLI (command line interface) to be installed on the machine. After login, we will be redirected to heroku dashboard which is similar to the below figure 18.1:
The above dashboard displays the available apps deployed on the cloud and to deploy a new application click on the New button available on the top-right corner which displays the below two options shown in the figure.
Click on the Create new app option which will redirect you to the below shown screen:
After entering the App name, message will be displayed if it is available or not (you must choose a unique name for your app) and the region selected can be seen in the above figure. After clicking on Create app, the following screen will be displayed describing about the procedure to be followed. As discussed, Heroku CLI is more prefered to deploy apps on heroku and can be installed from here - Heroku CLI.
The below screenshot displays the instructions to be followed for deployment.
Switch to the workspace where our project was created and open CMD in that location. Type the command heroku login (make sure that GIT and herkou CLI are installed properly in the system). It displays the message which can be seen in the below figure and type any key.
A New window will be opened on the browser asking the user to login. As we have already logged in the login screen will be something similar to the below figure.
The above figure displays the authentication process which will be displayed on the CMD after logging in as seen in the figure 18.6. The CMD was opened after switching to the workspace, incase if it is some other directory make sure to change directory to the workspace.
The above figure 18.8 is the content of the workspace where the project was created.
Follow the above commands as shown in the above figure:
git init=> Initializes the Git Repository in the specified directory.
heroku git:remote -a studytonight=> Establishes a remote with the Heroku cloud.
git add .=> Adding all the files which are required for deployment.
git commit=> Committing the after adding the files.
- We need to push the project to the Heroku cloud using the command git push heroku master.
The above figure 18.11 displays the final deployment message after successful deployment and the link to access our application on cloud is
https://studytonight.herokuapp.com which can be used to hit the Rest end-points.
Let us test the application on cloud as follows. We have enabled the swagger-ui which displays the available Resource end-points of the application.
Notice the URL in the figure 18.12 which is provided by heroku cloud.
Conclusion: In this tutorial, we have seen the deployment of spring-boot project on heroku cloud. The Application has many cloud specific states such as hibernate, awake, sleep which are specific to heroku cloud and depends on the number of active users using the application