Tag: springboot
-
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 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 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 deal with optional request parameters in Spring Boot?
Let’s say you are creating a REST API in Spring Boot which accepts request parameters. You use the annotation @RequestParam to retrieve the request values. And if user does not supply the request parameter Spring will throw error. What if the request parameter is just an optional parameter? How to handle this in Spring ?…
-
How to schedule tasks in Spring Boot?
Let’s say you want to schedule background tasks in your application , may be every ten minutes or at a fixed time every day or during weekends. How do you do that in Spring Boot? Spring Boot provides a simple and straightforward solution: By just using @Scheduled annotation. Here are the steps in detail: STEP1:…
-
What is @MapsId used for in JPA/hibernate? – Part 1
@MapsId annotation. If you ever wondered what this annotation is for , here is an in depth analysis of it: When is this annotation used? It is used if the primary key of a child table is the same as the primary key of a parent table Why is this used? By specifying the annotation…
-
How to write REST APIs for specific environments in Spring Boot?
Let’s say you want to write a REST API in Spring Boot and you also want it to be accessible only in specific environments , say development environment and not in test or production environments. How can you achieve this in Spring Boot? By using the @Profile annotation! Spring Boot has the provision to create…
-
How to call a REST API protected with SSL (https) from Spring Boot without importing the certificate into java keystore ?
In the previous post we saw how to consume a REST API protected with SSL (HTTPS) by importing necessary SSL certificates into JVM keystore That serves fine if you have access to the JVM . In case if you don’t and want to bundle those certificates along with your application and use it to call…
-
How to call REST API protected with SSL (https) from Spring Boot ?
Let’s say you want to invoke a REST API from your spring boot application. And it is protected with SSL. In other words you need an SSL certificate to access that application, else you won’t be given access to it. Your java keystore already has a lot of inbuilt certificates(In my local it is present…