Spring Boot web application with Gradle

1. Introduction

Before we move on to create our demo Spring Boot web application with Gradle, I assume we all are ready with the Gradle setup.

2. Creating Demo Application

Now that we ready with the plugin installed, create a new Gradle project as shown below –

Create Gradle Project in Eclipse

Clicking on Next, specify the project details as mentioned below –

Gradle Project Details in Eclipse

Click Finish and we are done with the initial project creation –

Gradle Project Structure

Like we have pom.xml with Maven, we have build.gradle with Gradle. Lets make the required changes to it by adding the Spring Boot dependencies –

Lets now create the SpringBootApplication class containing the main method –

SpringBootApplication Class


Similarly, let’s have a Spring controller class created as well –

Spring Controller class creation


We now need to add welcome.html in the Spring Boot resource location. Note that the resource folder might not exist while creating the Gradle project, so in my case I will have to create one explicitly.

Add resources folder to build path

Add resource folder in project

Resource location to build path

Project structure now should look like –

Gradle Project Structure

Now create ‘template’ folder inside the src/main/resource project directory, and create the welcome.html file inside it. Refer to the below snapshot –

Add Template file to the project

Next, Right-click on the project, go to ‘Gradle’ and click on ‘Refresh Gradle project’.

This is it.

3. Running the application

Right-click on the project and Run the application as Spring Boot App

Running the Spring Boot Gradle application

4. Download the source code

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.