The correct way to do @Async in Java Spring based applications

Spring provides an annotation @Async to run tasks in a separate thread. In Spring boot applications we can enable asynchronous tasks by adding the annotation @EnableAsync to any of the Spring configuration class as shown below: Now that we have the application setup to support asynchronous tasks, let us go ahead and create a simple … Read more

Execute around Aspect with @annotation pointcut in Spring Boot

Aspect oriented programming (AOP) is a programming model where we write independently executable code which adds additional behavior to the existing code without modifying the existing code. Wikipedia defines AOP as: In this article, I will show you how to execute certain code around the execution of a method which means I would execute some … Read more

Testing the File Upload API in Spring Boot

In one of my previous post, I had created an API to upload file. In this post I will write a JUnit test to test the API. We will test the complete flow right from uploading till it is copied to the file system and then we will also see how to mock the FileService … Read more

Upload files in Spring Boot application using Commons FileUpload

In our previous post, we saw how to upload a file using the Spring framework’s default implementation for MultipartFile interface. In this post, we will see how we can use the Commons FileUpload library and the wrapper implementation CommonsMultipartFile provided by the Spring framework. Update the pom.xml We will update the maven dependencies to include … Read more

Uploading files in Spring Boot application

Uploading files is one of the most common operations in a web application. In this article we will look at how to upload file from an HTML page and copy it to the file system on the server. Creating a HTML form with file upload option The below HTML code and its corresponding Javascript code … Read more

Using Websocket with Spring Framework and Vuejs

Websockets are full duplex (persistent) connections between client and server such that both can share information with each other without the need for repeatedly establishing a new connection. This removes the need for repeated polling from the client to get updates from the server. Not all browsers support Websockets and hence we make use of … Read more

Advanced profile management in Spring Boot

We all are aware of profile management in Spring Boot and the flexibility it provides in configuring our applications for different environments. The other powerful aspect of this is that at any given time we can have multiple active profiles. The advantage this gives is that we can mix the deployment environment profile along with … Read more

Integrate Spring Boot Application with Amazon Cognito

In this article, we will show how to use Amazon Cognito service for authentication users in a Spring Boot application using the OAuth 2.0 client library introduced in Spring Security 5.0. What is AWS Cognito? Amazon Cognito is service offered by AWS which provides user management services like sign up and sign in, in addition … Read more

Sample Logback Configuration for Spring Boot Profile Based Logging

We would want different logging configurations for different profiles in Spring Boot, like in local running we would just want console logging and for production, we would want file logging with support for rolling the log files daily. I came up with a sample logback configuration which I use in all my applications. Create a … Read more

Spring Boot: Thymeleaf Template Decorator Using Thymeleaf Layout Dialect

Introduction The question on reusing header and footer on all Thymeleaf templates has been often been asked on StackOverflow. In this article, I will show you how you can structure the templates using the Thymeleaf Layout Dialect to achieve a higher code reusability in a Spring Boot application. Create a Spring Boot Application Lets use … Read more

%d bloggers like this: