Author: Sergey Kargopolov

In this short tutorial, I am going to share with you how to enable CrossOrigin in a RESTful Web Service API build with Spring Boot and Spring MVC. And to do that you need to simply annotate a method in your RestController class with @CrossOrigin annotation like in the example below. Enable CrossOrigin @CrossOrigin(origins = “http://localhost:8080”) @GetMapping(path =…

Read More CrossOrigin in RESTful Web Service

In this tutorial, we will create a Spring Boot application which demonstrates how we can add and use the H2 in-memory database in our application. You will learn how an in-memory database like H2 can be used to develop a Spring boot application without an overhead of doing DB configuration on your machine and without…

Read More Using H2 In-memory Database with Spring Boot

In this REST Assured tutorial, I am going to share with you how to evaluate the JSON content returned in the Response Body of HTTP Response. JSON Content Returned in Response Body Let’s say we have a RESTful Web Service endpoint that returns user details of the following structure: { “userId”: “Y3vWa8QwjK0DW6NmvB4HsXIV9gHg1q”, “firstName”: “Sergey”, “lastName”:…

Read More REST Assured Evaluate JSON Response Body

In this tutorial, we will build a Spring Boot application which demonstrates how to access data in a MongoDB database using the MongoTemplate APIs.   For MongoDB, we will use mLab, which provides MongoDB Database as a Service platform so that you don’t even have to install a MongoDB database on your computer.  Also, at…

Read More Spring Boot and MongoTemplate Tutorial with MongoDB

In this short Java tutorial, you will learn how to quickly generate a serialVersionUID for a given class. Most Java IDEs provide a support for generating serialVersionUID automatically while some require you to install a plugin for you to generate this value. Generate SerialVersionUID for a Java Class There is a built-in command in JDK…

Read More How to Generate SerialVersionUID

In this Spring MVC tutorial, you will learn how to implement pagination in your RESTful Web Services app built with Spring MVC. The code example below will demonstrate how to implement pagination to implement “Get a list of users” registered with our app feature. I assume you already have your Spring MVC RESTful Web Service…

Read More REST Pagination Tutorial with Spring MVC

In this Spring MVC tutorial, you will learn how to make your RESTful Web Service endpoint respond back with either XML or JSON representation. To make your Web Service endpoint be able to respond with either XML or JSON representation include  MediaType.APPLICATION_JSON_VALUE  and MediaType.APPLICATION_XML_VALUE media types into the RequestMapping annotation of your resource method. For example: @GetMapping(path…

Read More Return XML or JSON in Spring MVC Web Service

In this Spring MVC tutorial, you are going to learn how to use the @PostMapping annotation to make your RESTful Web Service Endpoint be able to handle HTTP Post quest and read its JSON or XML body payload. Sending JSON in HTTP Post Request Let’s say we need to send the following JSON in our…

Read More @PostMapping and @RequestBody Example in Spring MVC