In today’s fast-paced software development landscape, deploying applications swiftly and efficiently is paramount. For developers working with Spring Boot, deploying on Railway.app offers an excellent solution. In this step-by-step guide, we will focus on “deploy spring boot application” and walk you through the process of deploying a Spring Boot application on Railway.app.
Railway.app simplifies the deployment of Spring Boot applications, making it accessible even to developers without extensive DevOps experience. The platform offers a user-friendly interface and a straightforward workflow to streamline the deployment process. This guide breaks down the steps, ensuring that both newcomers and experienced developers can successfully deploy their Spring Boot applications with ease.
We begin by outlining the prerequisites, including a Railway.app account and a Spring Boot application ready for deployment. Then, we delve into each step of the deployment process, from configuring your database to setting up environment variables. By the end of this guide, you will have a clear understanding of how to harness Railway.app’s capabilities to efficiently deploy your Spring Boot applications, making your development journey smoother and more productive.
Read More:
- Check the Complete JUnit 5 Tutorial
- Check the Complete JavaServer Faces (JSF) Tutorial
- Check the Spring Boot JdbcTemplate Tutorials
- Check the Complete Spring Boot and Data JPA Tutorials
- Check the Complete Spring MVC Tutorials
- Check the Complete JSP Tutorials
- Check the Complete Spring Boot Tutorials [100+ Examples]
- Check the Complete Spring Boot and Thymeleaf Tutorial
- Check the Complete AWS Tutorial
- Check the Complete JavaServer Faces (JSF) Tutorial
- Check the Complete Spring Data JPA Tutorial
- Check the Complete Spring Security Tutorial
- Check the Javascript Projects for Beginners
Table of Contents
Watch the Video
Create Spring Boot Project
There are many different ways to create a spring boot application, you can follow the below articles to create one –
>> Create spring boot application using Spring initializer
>> Create spring boot application in Spring tool suite [STS]
>> Create spring boot application in IntelliJ IDEA
Add maven dependencies
Open pom.xml
and add the following dependencies –
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.3</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>in.bushansirgur</groupId>
<artifactId>image-upload-download</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>image-upload-download</name>
<description>Spring boot image upload and download project</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Create a Controller
Create a class HomeController.java
under the default package and add the following content
package in.bushansirgur.demo;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HomeController {
@GetMapping({"/", "/home", "/status"})
public String getStatus() {
return "Application is up and running";
}
}
Run the app
Run the application using the below maven command –
mvn spring-boot:run
Create Github Repository
Login to your GitHub account, create a new repository
Once you create the repository, it will show you the instructions to push your code to Github.
Push the source code to GitHub
Open the terminal, go to the root of the project and execute the following commands
Note: Make sure that you installed git on your system before executing these commands
git init
This will initialize the git on your project
git add .
This will add all your files to the staging area
git commit -m "initial commit"
This will commit all your changes locally.
git remote add origin https://github.com/scbushan05/my-first-app.git
This will add the remote url to your project
git push origin master
This will push all your changes to GitHub, now your source code is available on GitHub.
Create an Account in Railway.app
You need to create a new account in Railway.app in order to deploy your Spring boot application. Don’t worry, it will not ask you to enter your credit/debit card details. Once you create an account, login to your account, your dashboard that look like this
Create a new project
Click on the New Project option to create a new project
You can choose Empty Project, it will create an empty project with a random project name.
Create a new Service
A project may contain multiple services, so go inside the project and create a new Service
For now, click on empty service, this will create a new service with a random service name.
Generate a Domain
Once you create a service, we need to generate the domain for our service, click on the service, go to settings, under the domains section, click on Generate Domain, it will create random domain for us.
Deploy Spring Boot Application to the service
Under the service settings, you will see the service source option, you can click Connect Repo option
It will ask you to choose the repository that you want to deploy, choose the repository which we created
As soon as you select the repository, it will start deploying automatically, you can see that under the deployments in the settings
For the first time, it will take few minutes, wait till it finishes the deployment. Once the deployment is done, you will see the deployment completed status. You can visit the generated URL milky-oatmeal-production.up.railway.app to see the application
That’s it for this post, if you like this post, share this with your friends and colleagues or you can share this within your social media platform. Thanks, I will see you in our next post.