Inject Prototype Bean into Singleton Bean in Spring – Lookup Method Injection

Lookup Method In this tutorial I am going to show you how lookup method injection works in Spring framework. You may face a situation where you need to inject prototype scoped bean into singleton scoped bean. For singleton scoped bean a new instance or object is created and the same is returned each time it is injected or looked up….

How to deal with Whitelabel Error Page in Spring Boot Applications

In this tutorial I am going to discuss about what is Whitelabel Error Page and how to deal with Whitelabel Error Page in Spring Boot applications. Spring boot allows you to setup a Spring based application with minimal configurations. Spring MVC applications provide no default (fall-back) error page out of the box but Spring Boot based applications provide a fall-back…

How to deploy Spring Boot Data JPA Application to Heroku Cloud

In this tutorial I am going to show you an example on deploying Spring Boot application to Heroku cloud. I will create a basic CRUD application with Spring Boot Data JPA and PostgreSQL/MySQL technologies. I will first show you how to perform CRUD operations locally, then deploy the same application in the Heroku cloud with some modifications. CRUD is an…

How to return Different Data Formats (JSON, XML) from Spring REST API

Introduction Here I am going to show you an example on how to return different data formats from REST API using Spring Boot framework. You may have a requirement that you need to return multiple formats, such as XML, JSON, etc., from the REST response, then this example may help you. This example will return XML and JSON format depending…

Mock an Autowired Value Field in Spring with Junit 5

Mock @Value In this example I am going to show you how to mock an autowired field in Spring boot framework with Junit 5. When you use @Value annotation in Spring beans to read the value from properties file and later when you want to perform Junit test then you also need to pass value for this autowired field value…

Spring Data JPA @NamedQuery and @NamedQueries Example

Introduction Spring Data JPA provides multiple ways of selecting or fetching data from database server and one of the ways is using @NamedQuery or @NamedQueries. @NamedQuery and @NamedQueries can be created using XML configuration, external properties file or using Java based annotation config. Spring Data JPA supports both JPQL and SQL native named queries. Here I am going to show…

How to generate PDF report from MySQL database in Spring Boot

I am going to show yo how to download PDF file from MySQL database using Spring Boot and iText library in Java programming language. Many applications require dynamic generation of PDF documents for reporting purpose, such as, generating statements for customers, readers buying online specific chapters of a book, etc. In my another tutorial I had shown how to create…

How to generate Excel Report from MySQL Database in Spring Boot

Here I am going to show you how to download excel file from MySQL using Spring framework. Generating excel report from MySQL database has few advantages over other file formats. Most of the people you are working with in your organization are familiar with excel file format, hence it needs a short learning curve. You may also like to read…

How to Trace Microservices Logs with Spring Cloud Sleuth and Zipkin

Introduction Here I am going to explain how to trace Spring Boot Microservices logs with Spring Cloud Sleuth and Zipkin Server. Spring Cloud Sleuth provides Spring Boot auto-configuration for distributed tracing. One of the problems most developers face difficulty of tracing logs as your microservices applications grow and requests propagate from one microservice to another microservice. So it could be…

Create, Build, Package and Run Spring Boot Application with Docker

Build And Package With Docker Here in this tutorial I am going to show you how to create a simple Spring Boot application. Then how to build, package and run this Spring Boot application with Docker in Linux environment (CentOS). I am going to use both gradle and maven as build tools for running build on this Spring Boot application….