Spring

In this short tutorial, I am going to share with you how to enable CrossOrigin in a RESTful Web Service API built with Spring Boot, Spring MVC and which also has Spring Security enabled. Enable CrossOrigin for Specific Endpoint  To enable cross origin AJAX HTTP request to a specific RESTful Web Service endpoint in our Rest Controller…

Read More CrossOrigin and CORS 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 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 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 request 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

Almost in every RESTful Web Service application, I have to do the DTO to Entity and then Entity to DTO conversion. DTO stands for Data Transfer Object and is a simple Plain Old Java Object which contains class properties and getters and settings methods for accessing those properties. In this blog post, I am going…

Read More DTO to Entity and Entity to DTO Conversion

With this Spring Boot tutorial, I am going to share with how to handle exceptions in your RESTful Web Service application build with Spring Boot. What If Exception Takes Place The good news is that if Exception takes place and your code does not handle it, Spring Boot will handle the Exception for you and will…

Read More Handle Exceptions in Spring Boot RESTful Service

It is extremely simple to add logging support to your RESTful Web Service application with Spring Boot. To use Spring Boot logging you do not really need to add any additional dependencies or libraries to your web app project other than the org.springframework.boot example of which is below. But if you are working on a Spring Boot…

Read More Spring Boot Logging with LoggerFactory