0% found this document useful (0 votes)
3 views

Spring Boot Setup

This document provides a step-by-step guide to setting up a Spring Boot project using Spring Initializer with Gradle. It includes instructions for configuring project settings, adding necessary dependencies, running the project, and accessing OpenAPI documentation and actuator endpoints. Additionally, it offers guidance on changing the Gradle home directory in IntelliJ to a specified location on the E drive.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Spring Boot Setup

This document provides a step-by-step guide to setting up a Spring Boot project using Spring Initializer with Gradle. It includes instructions for configuring project settings, adding necessary dependencies, running the project, and accessing OpenAPI documentation and actuator endpoints. Additionally, it offers guidance on changing the Gradle home directory in IntelliJ to a specified location on the E drive.
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Step 1: Set up Spring Initializer

Open your browser and navigate to the Spring Initializer website


(https://start.spring.io/).

<b>Project Settings:

Project: Select Gradle - Groovy.


Language: Select Java.
Spring Boot version: Select the latest Stable version (e.g., 3.x.x).
Group: Provide your project's group name (e.g., com.star.gmc).
Artifact: Provide your project's artifact name (e.g., policy-service).
Name: Provide a name for your project (e.g., policy-service).
Description: Provide a description (optional).
Package Name: This will auto-populate based on your group and artifact names.
Packaging: Choose Jar.
Java Version: Select 17.

Add Dependencies:

Spring Web (starter-web): For building web, including RESTful, applications using
Spring MVC.
Lombok (lombok): To reduce boilerplate code.
Spring Boot Actuator (starter-actuator): To monitor and manage your application.
Spring Boot Test (starter-test): For writing unit and integration tests.

Click the Generate button. This will download a ZIP file containing your Spring
Boot project.

Step 2: Unzip and Open the Project


Extract the downloaded ZIP file to your preferred directory.
Open the project in your preferred IDE (e.g., IntelliJ IDEA, Eclipse).
Step 3: Modify the build.gradle file by adding dependencies

Spring Validation (starter-validation): For handling validation.


Logstash Logback Encoder (net.logstash.logback:logstash-logback-encoder): To log
data in Logstash JSON format.
Logback Classic (ch.qos.logback:logback-classic): For logging.
Springdoc OpenAPI (org.springdoc:springdoc-openapi-starter-webmvc-ui): For auto-
generating OpenAPI 3 (Swagger) documentation.

Ensure that the build.gradle file contains the necessary dependencies. It should
look like the following:

groovy
<b> code
plugins {
id 'org.springframework.boot' version '3.x.x'
id 'io.spring.dependency-management' version '1.1.0'
id 'java'
}

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
implementation 'org.springframework.boot:spring-boot-starter-validation'
implementation 'org.projectlombok:lombok'
annotationProcessor 'org.projectlombok:lombok'
implementation 'net.logstash.logback:logstash-logback-encoder:7.2'
implementation 'ch.qos.logback:logback-classic:1.4.12'
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
useJUnitPlatform()
}
Step 4: Run the Project
To run the project, you can use the following command in the terminal:

bash
<b> code
./gradlew bootRun
This will start the Spring Boot application. You can then navigate to
http://localhost:8080 in your browser to test the app.

Step 5: Access OpenAPI Documentation


Once your application is running, you can access the auto-generated API
documentation via:

groovy
<b> code
http://localhost:8080/swagger-ui.html
This will open the Swagger UI where you can explore the API endpoints and
documentation for your Spring Boot application.

Step 6: Actuator Endpoints


To monitor and manage your application, Spring Boot Actuator exposes various
endpoints like /actuator/health and /actuator/info. You can access them using:

groovy
<b> code
http://localhost:8080/actuator/health
These steps should get your Spring Boot project up and running with the required
dependencies.

change to E drive:

*) In Intellij, File -> Setting and search as gradle.


Gradle window opens, Change the gradle home to folder in E drive. Make sure to have
new folder created in E drive.
Also change gradle jvm to have appropriate version of java using in the project.

You might also like