Getting started with Spring Boot

This will be a basic guide/overview of Spring Boot. Subsequent series (not planned at the time of writing) might contain more in-depth usage for spring boot.

Spring Boot is backend framework to bootstrap your application. You can skip a lot of boilerplates when using Spring Boot.

Note: Always use a dependency manager to create these kinds of projects. Why?

  • You don’t need to deal with dependency jar files.
  • When uploading to GitHub, you only need to upload your code rather than dependencies.
Project Structure

We will be creating HelloWorld2 project, which is a REST API of Person.

We can create a spring boot application using

  • pom.xml

This file is the config file for any maven project.

Group ID is usually your website name.

Artifact ID is the unique name for your project.

  • com.arjunsk.HelloWorld2 / Application.Java

The naming is < Group ID >+ < Artifact ID >/ MainFunction Class

Note: The main function class should be created in the base package.

  • com.arjunsk.HelloWorld2.controllers /

A controller is a glue between Model & View. Here you will code the URL REST patterns and there functions.

  • com.arjunsk.HelloWorld2.models /

Model is the database table.

  • com.arjunsk.HelloWorld2.repositories /

The repository basically allows you to decouple your business logic from your database layer.

Your model knows how to find all records for a given entity, your repository could wrap that in business-specific logic.

  • src/ main / resources /

Contains the property for the database. Make sure your values match with the one shown in http://localhost:8080/h2-console

# Enabling H2 Consolespring.h2.console.enabled=truespring.datasource.url=jdbc:h2:~/testspring.datasource.driverClassName=org.h2.Driverspring.datasource.username=saspring.datasource.password=
  • src / main / resources / data.sql

The following inserts these value whenever the H2 database is initialized.

Note: H2 is an in-memory database. So data will be deleted when the instance is closed.

insert into Person values(101,'Arjun');insert into Person values(102,'Sagar');
REST response

Found it Interesting?
Please show your support by 👏.

I myself have just started learning, Spring Boot. If you find any issues please feel free to post them in the comments section below. Thank you for reading so far 😄

Writes on Big Data, AWS & Backend technologies.

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