How to start a spring boot project for your backend.

The fastest way to start a spring boot project.
So you want to start your backend in spring boot. I will show you how to create a runnable spring boot app in a couple of minutes.
When it comes to scaffolding, Spring boot gives a lot of options. and one of the starting points in creating a new spring boot project is Spring Initializr
Go to https://start.spring.io/
In the project, select Maven. For language, you can select Java, and fill in the basic details about the project name, artifact name, and other things. and click Generate

Open the project. you should see something like below

Let's create a basic rest API in our project.
go to your pom.xml
and add the following dependency.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
Now that you have spring web dependency, it's time to create our Controller which will be having the API.
Let's create a controller class HealthController.java
and add the following code.
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@CrossOrigin(origins = "*")
@RestController
@RequestMapping("/health")
public class HealthController {
@GetMapping("/")
ResponseEntity sample() {
return ResponseEntity.ok().build();
}
}
Ok, so now that we have our API endpoint ready, it's time to run it.
Run your application class, in my case its DemoApplication.java
and that’s it. you should be able to access your API via 127.0.0.1:{your_port_number}/health
Cheers!!