Spring Boot - Continuous Integration Using GitHub Actions
Last Updated :
24 Apr, 2025
Let's say we have two or more developers who are merging code into a single repository. There can be issues in merging code from different developers. So the Continuous Integration tools help in solving not just that but many other things like:
- Run an automated build after successful merging (like build, test code coverage, etc.).
- We can also automate deployment after proper checks.
- Not just that, these platforms also provide a way to communicate with others with comments to let's say, solve a merging conflict or review a pull request.
- It also helps in running it on different OS.
One of the tools that we will be using here is GitHub Actions to accomplish our CI workflow. It is a powerful tool that can be utilized for continuous deployment as well.
Prerequisites:
- Keep IntelliJ Community(or related IDE)
- GitHub account
- JDK 11 and gitbash (or a related tool to push code)
Step-by-Step Implementation
Step 1: Let's create a basic Spring boot project first
a). Go to https://start.spring.io/
- Project: Maven | Language: Java | Spring Boot: 2.7.14
- Project Metadata:
- Group: com.example | Artifact: demo-springgithubactions | Name: demo-springgithubactions
- Description: Demo project for Spring Boot with GitHub actions
- Package name: com.example.demo-springgithubactions
- Packaging: Jar | Java: 11 | Dependencies: Spring Web
b). Open in IntelliJ. Run the following command in the terminal
./mvnw clean install
c). Create following folders (....\demo-springgithubactions\.github\workflows\build.yml) and file (build.yml) which will be detected and used by github to run workflows using github actions.

d). Update the file with following code
name: Build a JAR in spring boot using springboot
on:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: '11'
- name: Build with Maven
run: mvn clean install
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v2
with:
name: java-app
path: '${{ github.workspace }}/target/*.jar'
- name: Run Tests
run: mvn test
e). Create following folders (....\src\main\java\com\example\demospringgithubactions\controller\HelloWorld.java) and file (HelloWorld.java).

f). Update the file with following code.
Java
package com.example.demospringgithubactions.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorld {
@GetMapping
public String hello()
{
return "<!DOCTYPE html>\n"
+ "<html>\n"
+ "<head>\n"
+ "<style>\n"
+ "h1 {text-align: center;}\n"
+ "</style>\n"
+ "</head>\n"
+ "<body>\n"
+ "\n"
+ "<h1>Yaay!! you did it XD</h1>\n"
+ "\n"
+ "</body>\n"
+ "</html>\n";
}
}
g). Create following folders
(....\src\test\java\com\example\demospringgithubactions\DemoSpringgithubactionsApplicationTests.java) and file (DemoSpringgithubactionsApplicationTests.java).
h). Update the file with following code.
Java
package com.example.demospringgithubactions;
import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import com.example.demospringgithubactions.controller.HelloWorld;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
@RunWith(SpringRunner.class)
@WebMvcTest(HelloWorld.class)
class DemoSpringgithubactionsApplicationTests {
@Autowired
private MockMvc mockMvc;
@Test
public void checkSuccessMessage() throws Exception
{
this.mockMvc
.perform(get("/"))
.andExpect(status().isOk())
.andExpect(content().string(
containsString("Yaay!! you did it XD")));
}
}
i). Run the code and verify if you are able to hit "http://localhost:8080/" end point with message dispalyed "Yaay!! you did it XD".
Step 2: Let's push our code to GitHub
git init
git add -A
git commit -m 'Added my project'
git remote add origin <github-ssh-url>
git push -u -f origin main
Step 3: Go to Github actions tab and you will see the job running automatically

Similar Reads
Spring Boot - Auto-configuration
Spring Boot is heavily attracting developers toward it because of three main features as follows: Auto-configuration - such as checking for the dependencies, the presence of certain classes in the classpath, the existence of a bean, or the activation of some property.An opinionated approach to confi
5 min read
How To Set Up Continuous Integration With Git and Jenkins?
Continuous Integration (CI) is a practice where developers integrate their code into a shared repository frequently, ideally several times a day. Each integration can then be verified by an automated build and automated tests. This practice helps to detect errors quickly and improve software quality
4 min read
Integrating Apache HttpClient in Spring Boot
Spring Boot is a powerful Java-based framework for building web-based applications with microservices. We know that one common requirement for any application is to fetch the data from another site also for that we have to use API to do the task of fetching and storing the data from and to the datab
4 min read
Containerizing Spring Boot Application
Java applications, known for their robustness sometimes become difficult to deploy and manage. This is where containerization comes into the picture. Packaging your Java app into a lightweight and self-contained independent unit can provide many benefits to the developers: PortabilityScalabilityFast
3 min read
Integrating Ansible with GitHub for CI/CD Pipelines
Many development teams face challenges when successfully combining several tools to form proper and effective CI/CD processes. An inefficient workflow means projects slow down, vary in their implementation, and have more overhead related to infrastructure management. Another consequence is that, due
8 min read
Configuring Spring Boot Applications with Maven Profiles
In a software development environment, applications must often be configured differently for various environments such as development, testing, and production. Managing these configurations can be challenging, but Maven provides powerful features called profiles to handle this. Maven profiles allow
5 min read
Microsoft Azure - Using Github Action in Azure App Service
In this article, we will learn how to use GitHub Actions from Azure App Service. GitHub Actions enables us to automate builds and deployments which results in better quality software. For the purpose of demonstration, let's use it from this Azure App Service Web App that we've already created. This
2 min read
Flutter - Building and Releasing APK using GitHub Actions
Github Actions is a Github tool that allows users to create CI/CD pipelines directly in a Github project instead of going to a third-party website. It assists us in developing, testing, and releasing our project very conveniently. In this article, we're going to build a workflow for our Flutter proj
3 min read
How to Set Up a CI Pipeline for Ktor Using GitHub Actions?
In this article, we'll look at how to use GitHub Actions to create a robust and effective Continuous Integration (CI) pipeline for Ktor applications. Developers have a great foundation to construct high-performance server-side apps thanks to Ktor, a versatile and lightweight Kotlin framework for bui
6 min read
Automated Release for Android Using GitHub Actions
Automating the release process for Android applications can significantly enhance efficiency, reduce manual errors, and ensure consistent delivery. GitHub Actions provides a powerful platform to automate workflows directly from your GitHub repository. This article will guide you through setting up a
3 min read