How To Build Web Service Using Spring Boot 2x

How To Build Web Service Using Spring Boot 2x

Do you want to create a web-service application using spring boot? Then please check this architecture template. Let it be a kick for your starting.

Architecture Contains

  • MVC Architecture
  • JWT Based Authentication
  • Spring Data (JPA)
  • Application User Password Encryption
  • DB password Encryption.
  • SQL Server
  • Log4j2
  • Swagger For API Doc

Repository Contains

  • Application Source code.
  • SQl script of Data Base along with key data.
  • DB.txt file contains the DB config details.
  • Postman JSON script to test all web-services.

Steps to Run Applications

  • Install JDK 11 or latest.
  • Clone the Project repository into local.
  • Git Url : https://github.com/VishnuViswam/sample-web-service.git
  • Install SQL server 2012.
  • Create application DB and user
  • Insert the DB key data.
  • Add the decoding key of the database password into the system variables. It is present in DB.txt file.
  • Sometimes we may need to restart the windows to pick up the updated system variables.
  • Run the project source code.
  • To call the web-services, import provided postman JSON scripts into the postman client application.

About Project Configurations

Web-Service Declaration

Each Web-services of application will be declared in the controller layer.

Example

Java

@RequestMapping("/api/v1/user")
@RestController
public class UserController {
    private static final Logger logger = LogManager.getLogger(UserController.class);
    @Autowired
    private GeneralServices generalServices;
    @Autowired
    private UserService userService;
    @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Object> createUser(HttpServletRequest httpServletRequest,
                                             @RequestBody CustomUser user) {
        logger.info("<--- Service to save new user request : received --->");
        ApiResponse apiResponse = userService.createUser(user, generalServices.getApiRequestedUserId(httpServletRequest));
        logger.info("<--- Service to save new user response : given --->");
        return ResponseEntity.status(HttpStatus.CREATED).body(generalServices.buildJsonData(apiResponse));
    }
}
  • @RequestMapping("/api/v1/user") annotation used to mention the category of web service.
  • @RestController annotation will configure the class to receive the rest-full web service call.
  • @PostMapping() annotation will decide the HTTP request type.
  • consumes & consumes tags will decide the content type of the HTTP request and response.

From this "controller layer" API request will be taken to the service layer. All business logic will be handled here, then it will talk with the database using JPA.

java tutorial microservices jpa spring security web service spring boot 2 jwt authentication log4j2 mvc architecture

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Spring Boot - Spring Security + JWT Complete Tutorial With Example

Learn how to implement spring security using JWT (JSON Web Token). What is JWT? Why JWT? JSON Web Token (JWT) is a compact URL-safe means of representing claims to be transferred between two parties. Spring Boot - Spring Security + JWT Complete Tutorial With Example

How To Set Up Two-Factor Authentication in cPanel

What is 2FA Two-Factor Authentication (or 2FA as it often referred to) is an extra layer of security that is used to provide users an additional level of protection when securing access to an account.

How to Build a Token-based authentication server using Spring Boot and Spring Security

In this post, we'll look at how to Build a Token-based authentication server using Spring Boot and Spring Security

Secure Service-to-Service Spring Microservices with HTTPS and OAuth 2.0

This tutorial showed you how to make sure your service-to-service communications are secure in a microservices architecture. You learned how to use HTTPS everywhere and lock down your API with OAuth 2.0 and JWTs.

Spring Web Flux UI with Spring Security

Take a look at how to construct an application using Spring Web Flux and Thymeleaf, with Spring security, a gateway services, and other microservices.