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

Building A Basic Spring Boot Application

Uploaded by

Dheeraj Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Building A Basic Spring Boot Application

Uploaded by

Dheeraj Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Here's a step-by-step guide to building a basic Spring Boot application:

1. Project Setup:

● Use Spring Initializr: Visit https://start.spring.io/ and fill in the project details:
○ Group: com.example
○ Artifact: my-demo-app
○ Dependencies: Add "Spring Web"
○ Build tool: Choose Maven or Gradle
○ Java version: Select your preferred version
● Generate Project: Click "Generate" and download the project zip file.
● Extract the zip file: Unzip the downloaded project to your workspace.

2. Create Main Application Class:

● Navigate to src/main/java/com/example/mydemoapp: Open this package in


your IDE.
● Create a class named DemoApplication.java: Paste the following code:

Java
package com.example.mydemoapp;

import org.springframework.boot.SpringApplication;
import
org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication

public
class
DemoApplication
{

public
static
void
main(String[] args)
{
SpringApplication.run(DemoApplication.class, args);
}
}

“This is written by Bard AI”


3. Create a Simple Controller:

● Create a class named HelloController.java in the same package: Paste the


following code:

Java
package com.example.mydemoapp;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController

public
class
HelloController
{

@GetMapping("/hello")

public String hello()


{
return
"Hello, Spring Boot!";
}
}

4. Run the Application:

● From IDE: Run the DemoApplication class as a Java application.


● Command line (Maven):
○ Navigate to the project root directory.
○ Run mvn spring-boot:run.
● Command line (Gradle):
○ Navigate to the project root directory.
○ Run gradle bootRun.

5. Test the Application:

● Open a web browser: Go to http://localhost:8080/hello (assuming the default


port).

“This is written by Bard AI”


● You should see the response: "Hello, Spring Boot!"

Congratulations! You've successfully built and run a basic Spring Boot


application!

Explore further:

● Add more controllers and features: Build upon this foundation to create more
complex applications.
● Refer to Spring Boot documentation: Get detailed information on various
features and configurations:
https://docs.spring.io/spring-boot/docs/current/reference/html/:
https://docs.spring.io/spring-boot/docs/current/reference/html/
Sources
1. https://github.com/dnilay/sg-jenkins
2. https://www.split.io/blog/controlled-rollouts-java/
3.
https://cloud.google.com/appengine/docs/standard/java-gen2/building-app/writing-web-s
ervice
4. https://github.com/1134923982/springboot_exercise
5.
https://repositorio.ufrn.br/bitstream/123456789/28895/1/Improvingbuglocalization_Medei
ros_2020.pdf

“This is written by Bard AI”

You might also like