RESTful Web Services

Spring Boot has a nice feature which enables the application to automatically restart when you make a change to your Java code. This automatic restart of your application is often called Hot Swap. Spring Boot Dev Tools Dependency To enable your Spring Boot application to automatically restart when you make a change to your Java…

Read More Spring Boot Hot Swap or Automatic Restart

In this tutorial on Spring Framework you will learn how to use constructor-based dependency injection(DI) in Spring Framework when building RESTful Web Services. Injecting an Object Let’s assume we need to inject a Utility class into a Service class we have. Below is an example of a UserService class which uses Constructor-Based dependency injection to…

Read More Constructor-Based Dependency Injection in Spring

In this tutorial, you will learn how to use the @Autowired and @Qualifier annotations together to auto wire a specific Bean. Sometimes you might have more than one Bean of the same type and if you do not explicitly specify which one you would like to auto wire, you will get an NoUniqueBeanDefinitionException when starting up…

Read More How to Use @Autowired and @Qualifier in Spring

In this short Spring Boot tutorial, you will learn how to pass command-line arguments to your Spring Boot application. Passing Command-Line Arguments To pass command line arguments to your Spring Boot app when running it with Maven use the -Dspring-boot.run.arguments. In the below code example, I will pass two command-line arguments: firstName and lastName. mvn spring-boot:run…

Read More Pass Command-Line Arguments to Spring Boot Application

In this Spring MVC tutorial, you will learn how to read HTTP Request Header in the Rest Controller class of your Application. To read HTTP Request Header in Spring MVC application we use @RequestHeader annotation. @RequestHeader(value=”Accept”) String acceptHeader Reading HTTP Request Header For example, let’s assume we need to create a method in our Rest…

Read More Read HTTP Request Header in Spring MVC

In this Swagger tutorial, I am going to share with you how to add Contact and API information to your RESTful Web Service documentation created with Swagger. When adding Swagger to our RESTful Web Service, we usually create a new configuration Java Class which is then annotated with @Configuration annotation. Below is an example of…

Read More REST API Contact and ApiInfo with Swagger

In this tutorial, you will learn how to add Swagger or an OpenAPI support to your Spring Boot project so that you can start documenting your REST API. To be able to follow this tutorial you will need to have your REST API Spring Boot project created. If you do not have one, here is…

Read More How to Add Swagger to a Spring Boot REST API Project

In this tutorial, you will learn how to deal with an infinite recursion problem or circular reference which takes place when you try to return an Object with Bidirectional Relationships in the body of HTTP Response. Infinite Recursion Problem Let’s have a look at an example which will cause an Infinite Recursion problem in our RESTful Web…

Read More Infinite Recursion in Objects with Bidirectional Relationships

In this short tutorial, you will learn how to rollback a database change using @Transactional annotation in your RESTful Web Service built with Spring MVC and JPA. Rollback with @Transactional Annotation Sometimes if an error takes place in our RESTful Web Service we want to rollback the changes made. For changes to be rolled back…

Read More Rollback Using @Transactional in Spring with JPA

In this blog post, I am going to list commonly used POM.XML dependencies for building RESTful Web services with Spring Boot and Spring MVC. The list of below dependencies is not complete and will depend on the functionality you need your RESTful Web Services to support. But if you are building a simple REST API…

Read More Common POM.XML Dependencies for RESTful Web Services