Java

Spring Boot has a nice feature that enables the application to automatically restart when you change 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 code, add the…

Read More Spring Boot Hot Swap or Automatic Restart

This tutorial will teach you how to use constructor-based dependency injection(DI) in Spring Framework when building RESTful Web Services. Read the following tutorial to learn about the different types of dependency injection in Spring and which one may be better suited for your specific use case. Constructor-Based Dependency Injection Overview Constructor-based dependency injection is a…

Read More Spring Constructor-Based Injection

In this tutorial, you will learn how to use the @Autowired and @Qualifier annotations to inject a specific instance of a Bean. Sometimes you might have more than one implementation of an interface. If you do not explicitly specify which one you would like to inject, you will get a NoUniqueBeanDefinitionException when starting your application. Let’s…

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 tutorial, you will learn how to read HTTP Request Header in the Rest Controller class of your Spring Boot application. To read HTTP Request Header in Spring Boot REST application, we use @RequestHeader annotation. @RequestHeader(value=”Accept”) String acceptHeader To learn how to test if HTTP Header is received, read the tutorial about Testing HTTP Header…

Read More Read HTTP Request Header in Spring Boot REST

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

If your project uses Spring Security and you have added Swagger/OpenAPI to it, there is a little additional configuration you need to do in order to make your /v3/api-docs and swagger-ui.html pages work. Enable Swagger URLs in Spring Security Project To enable Swagger URLs in a RESTful Web Services project built with Spring Boot and…

Read More Swagger/OpenAPI and Spring Security

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 occurs when you try to return an Object with Bidirectional Relationships in the HTTP response body. Infinite Recursion Problem Let’s look at an example that will cause an Infinite Recursion problem in our RESTful Web Service when we…

Read More Infinite Recursion in Objects with Bidirectional Relationships

This short tutorial will teach you how to roll back a database change using @Transactional annotation in your RESTful Web Service built with Spring Boot and JPA. Rollback with @Transactional Annotation Sometimes if an error occurs in our RESTful Web Service, we want to roll back the changes made. For changes to be rolled back…

Read More Rollback Using @Transactional in Spring with JPA

This tutorial will teach you how to create a JPA Native SQL Query to only select information from specific columns. You can find many more Spring Data JPA-related tutorials on this site. Some of the most popular tutorials are: One-to-One Mapping Hibernate/JPA Using Spring Boot and MySQL One-to-Many Mapping Hibernate/JPA Using Spring Boot and MySQL…

Read More Select Specific Columns with JPA Native Query

In this tutorial, I will share how to make the Spring Boot application display Hibernate SQL Queries. If you are learning about Hibernate, you might also be interested in the following tutorials: One-to-One Mapping Hibernate/JPA Using Spring Boot and MySQL One-to-Many Mapping Hibernate/JPA Using Spring Boot and MySQL Many-to-Many Relationship in Spring Boot Rest +JPA…

Read More Show Hibernate SQL Query in Spring Boot