Skip to content

SnehalKaranje/springboot-blog-rest-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

springboot-blog-rest-api

maven Spring Boot Java 11 MySQL

Dependencies

Dependencies used are as follows:

spring-boot-starter-web spring-boot-starter-data-jpa mysql-connector-java lombok spring-boot-devtools spring-boot-starter-test model-mapper spring-boot-starter-validation

Project Architecture

3 layer Architecture : Client <--> Controller <--> Service <--> DAO <--> DB

- Controller
  - Keeps all spring REST controllers
  - Define end points
- Service
  - all service classes that hold business logic
- DAO
  - Repository layer
  - keep all spring JPA data repository
  - Communicates with database

Project Structure Explained

- controller
  - Contains all Spring MVC controllers
- entity
  - Contains all JPA entities
- service
  - Contains service interfaces
- service.impl
  - Contains servie classes
- utils
  - Contains utilities and classes
- repository
  - Contains Spring Data JPA repositories. (JPA repositories are by default Transactional. Default implementation class of the JpaRepository interface is SimpleJpaRepository class)
- exception
  - Contains all custom exceptions
- payload
  - Contains DTOs (Data Transfer Objects) that act as a payload between client and server

API document generation

OpenAPI 3 specification document for API is auto generated using springdoc-openapi-ui

As per custom path provided in application.properties, auto generated API doc is generated at custom path:

http://localhost:<port>/api-docs/ 

Doc can also be accessed in the Swagger UI at path:

http://localhost:<port>/swagger-ui.html

Annotations

Spring Boot Annotations

SpringBootApplication ResponseStatus Service RestController Controller ResponseBody RequestMapping PostMapping GetMapping PathVariable PutMapping DeleteMapping RequestParam Bean ExceptionHandler ControllerAdvice

Lombok annotations

Data AllArgsConstructor NoArgsConstructor

JPA annotations

Entity Table Id GeneratedValue Column ManyToOne JoinColumn OneToMany

Spring Boot starter validation (Hibernate Validator)

NotNull Size Min Max Email NotEmpty NotBlank Valid