Tag: springboot
-
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…
-
How to create a custom annotation in Spring Boot?
Annotation is a powerful feature in Java. You can plug in some logic by just adding a word ! Consider this annotation in Spring Data: @Transactional Add this to a method where you are performing a sequence of database operations and they suddenly turn transactional. If any of the database operation fails all the other…
-
How to automate java bean to bean mapping in Spring Boot using MapStruct?
Let’s say you are developing an application which fetches data from the database. Let’s say you are using hibernate to do the object relational data mapping. So the data you fetch from database are mapped into Java entity objects . And then you extract data from this entity object into another java bean object (DTO/data…
-
How to automate database migration in Spring Boot using flywaydb?
Let’s say you want to migrate your database to another environment. For example , you have your database set up in development environment and you want to migrate that to test environment. The traditional way to do that is to create scripts for each database change , store them in a file and fire them…
-
How to redirect to an external URL from Spring Boot REST Controller (Post/Redirect/Get pattern)?
Let’s say you want to redirect users to an external URL when they make an API request. How to do this in Spring Boot? There are two ways you can do this. One using ResponseEntity object Two using RedirectView object. Here is how to do it with ResponseEntity object: STEP1: Create a REST Controller which…
-
How to interpret and modify REST requests in Spring Boot in a centralized way?
Let’s say you have created a bunch of REST services in your Spring Boot app. And you want to perform a common action on all the requests. May be you want to log the incoming requests to a log file. Instead of doing this action for every REST service you can do it in a…