Category: Spring Boot

  • How to do client side load balancing in Spring Boot?

    Let’s say you have created a set of microservices. They communicate to each other through a service registry like Eureka. One shortcoming in communicating through service registry is load balancing is not taken care of by default. You need to take care of that through a client side load balancer or a service side load…

  • How to talk to services in a service registry in Spring Boot?

    In this post we saw how to set up a service registry in Spring Boot. You can register all your microservices in a single service registry which will make it easier for each microservice to communicate with each other. In this post let’s see how to do the communication part. How can a microservice discover…

  • How to set up a Service Registry in Spring Boot?

    Let’s say you have created few microservices. They talk to each other. You manually configure the URL of each microservice which each microservice talks to. You add them in application.yml files. Maintaining them can be difficult. And if there are multiple instances of each microservice , you may need to configure each instance URL or…

  • How to fetch configuration data from config server in Spring Boot?

    Let’s say you have created a Spring Boot application and you fetch properties from application.yml file. Every time you want to change a property you need to restart your application. And if there are few more projects having similar configuration you need to replicate the properties in those applications as well. To solve this ,…

  • How to invoke OAuth2 protected microservice using WebClient in Spring Boot?

    Let’s say you want to call an OAuth2 protected microservice from your Spring Boot microservice application. Spring Boot as usual does majority of the work for us. We just need to add a dependency ,some configuration and using a single HTTP call using Spring Web Client we can invoke the microservice. Before that , to…

  • How to protect your Spring Boot microservice with OAuth2?

    Protecting your microservice developed in Spring Boot is quite forward. Spring does all the major work for you. Here are the steps to follow: STEP 1: Add spring boot starter oauth2 resource server dependency STEP 2: Configure Authorization Server STEP 3: Test STEP 1: Add spring boot starter oauth2 resource server dependency Add the below…

  • How to set up KeyCloak for OAuth2 client credentials flow?

    We live in the age of microservices. Microservices are often deployed as REST APIs. And the most popular way to protect and access these REST APIs is through OAuth2 protocol. And in OAuth2 protocol ,the preferred way to protect REST APIs is through client credentials. To set this, You first need an Identity and Access…

  • How to prevent basic auth pop up for invalid credentials in Spring Boot REST API?

    Let’s say you have created a backend REST API application in Spring Boot. Your front end application is deployed separately and it communicates with the backend via REST API calls. You decide to protect the backend with Spring Security. You also decide to use inbuilt Spring mechanism to validate login. So to authenticate a user…

  • How to restrict users from uploading huge files in Spring Boot?

    Let’s say you have created a REST API which accepts files as input. You deployed the API and users started uploading huge files and your server’s memory gets fast filled up. How do you prevent this? You can do this with zero code changes in Spring Boot. All you have to do is add a…

  • How to create a custom Health Check in Spring Boot for Microservices?

    Let’s say you have three microservices in your application. One of the microservices connects to the other two microservices. And in addition it also connects to a database. You want to check the health status of this microservice and its dependent microservices and database. How to do this in Spring Boot? Spring Boot provides an…