How to start a spring boot project for your backend.

Photo by Med Badr Chemmaoui on Unsplash

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

Spring Initializr

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!!

--

--

--

1profile.link/manoj

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Mental Models For Queues In User Interfaces

Microservice Architecture Explained Part-1

Rust Guide: Sum-Check protocol

How To Create RPM Packages & Why You Should

{UPDATE} jacht & overleven Hack Free Resources Generator

When to use Serenity Ensure Instead of a Questions Class for your Assertions with Screenplay and…

espeak-ng in Linux

My internship at Breather (Fall 2017)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Manoj Ahirwar

Manoj Ahirwar

1profile.link/manoj

More from Medium

How To Configure and Deploy WebApps with Wildfly Application Server in IntelliJ IDEA

7-Steps to Create Jenkins Maven Project Job

List of different project and you need to choose the Maven project

AWS EC2 with Java SDK — Part 2

What are Docker, Containers, Virtual Machines, and Containerization?