Spring boot is module of spring framework which we speed up the development,It' s provides an easier and faster way to set up, configure and run both simple and web-based applications.
- Scan the class path and find the dependency it will automatically configure the things.
- define controller folder in the Main class folder or main package
- https://spring.io/projects (MAIN DOCUMENTATION)
- chillotech - YouTube (AFRICA TOP tuto)
- The Dev World - by Sergio Lema - YouTube
- Bouali Ali - YouTube
- https://www.youtube.com/@TheDevWorldbySergioLema (top angular+spring boot)
- https://www.youtube.com/@LearnCodeWithDurgesh
- https://www.youtube.com/@CodeJava
- https://www.youtube.com/@DanVega
- Spring I/O - YouTube
- https://spring.io/guides
- https://www.youtube.com/@DailyCodeBuffer
- Code Elevate - YouTube (Spring boot + angular)
- https://www.youtube.com/@codwithzosh
- EnggAdda - YouTube
- https://www.youtube.com/@TeddySmithDev
- Code Decode - YouTube (INTERVIEWS)
src
├── main
│ ├── java
│ │ └── com
│ │ └── yourcompany
│ │ └── yourproject
│ │ ├── config (Application configuration classes)
│ │ ├── controller (REST API controllers)
│ │ ├── exception (Custom exception classes)
│ │ ├── model (Data model classes)
│ │ ├── repository (Database repositories)
│ │ ├── service (Business logic services)
│ │ ├── util (Utility classes)
│ │ ├── Application.java (Main application class)
│ │ └── ...
│ ├── resources
│ │ ├── static (Static resources like CSS, JS, images)
│ │ ├── templates (HTML templates, if using server-side rendering)
│ │ ├── application.properties (Application-wide properties)
│ │ ├── application.yml (YAML configuration, if preferred)
│ │ └── ...
└── test
├── java
│ └── com
│ └── yourcompany
│ └── yourproject
│ ├── controller (Controller test classes)
│ ├── service (Service test classes)
│ ├── util (Utility test classes)
│ ├── ApplicationTests.java (Main test class)
│ └── ...
└── resources
├── application.properties (Test-specific properties)
└── ...
Explanation of Key Folders:
-
config: Contains configuration classes, such as beans, security configurations, and other application-wide settings.
-
controller: Houses your REST API controller classes, which handle incoming HTTP requests.
-
exception: Contains custom exception classes, which you can use to handle application-specific errors.
-
model: Stores data model classes, representing your application's entities.(entity,dto)
-
repository: Holds database repository interfaces or classes if you're using a database.
-
service: Houses business logic services that orchestrate interactions between controllers and repositories.
-
util: Contains utility classes that are used across the application.
-
static: This folder holds static resources like CSS, JavaScript, and images, typically used for web applications.
-
templates: If you're using server-side rendering with templating engines like Thymeleaf, this is where your HTML templates would reside.
-
application.properties/application.yml: Configuration files for properties that configure your application. They include database settings, logging levels, etc.
-
test: This folder mirrors the
main
folder's structure but is dedicated to test classes and resources.
logging.file.path=C:/Users/kpidi/logs
Application Properties support us to work in different environments. In this chapter, you are going to learn how to configure and specify the properties to a Spring Boot application.
we can keep separate properties file for each profile as shown below −
application.properties
server.port = 8080
spring.application.name = demoservice
application-dev.properties
server.port = 9090
spring.application.name = demoservice
application-prod.properties
server.port = 4431
spring.application.name = demoservice
The application.properties file is not that readable. So most of the time developers choose application.yml file over application.properties file. YAML is a superset of JSON, and as such is a very convenient format for specifying hierarchical configuration data. YAML is more readable and it is good for the developers to read/write configuration files. For example, let’s pick some of the properties files that we have explained above, and let’s write them in YAML format.
JpaRepository
extends PagingAndSortingRepository
which in turn extends CrudRepository
.
Their main functions are:
CrudRepository
mainly provides CRUD functions.PagingAndSortingRepository
provides methods to do pagination and sorting records.JpaRepository
provides some JPA-related methods such as flushing the persistence context and deleting records in a batch.- JpaRepository docs(Derived Query Methods in Spring Data JPA Repositories | Baeldung , JpaRepository (Spring Data JPA Parent 3.1.1 API) )
Because of the inheritance mentioned above, JpaRepository
will have all the functions of CrudRepository
and PagingAndSortingRepository
. So if you don't need the repository to have the functions provided by JpaRepository
and PagingAndSortingRepository
, use CrudRepository
.