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.
Why 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.
We will be creating HelloWorld2 project, which is a REST API of Person.
We can create a spring boot application using https://start.spring.io/
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 / PersonController.java
A controller is a glue between Model & View. Here you will code the URL REST patterns and there functions.
- com.arjunsk.HelloWorld2.models / Person.java
Model is the database table.
- com.arjunsk.HelloWorld2.repositories / PersonRepositiory.java
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 / application.properties
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');
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 😄