Natural Programmer's Blog

Topics on Spring Framework for developing elegant real-world applications

Using Postman REST Client Cleverly - Some Quick Tips

Postman is one of the most popular API development environments, which needs no introduction to API developers. But strangely, numerous API developers often ignore many of its key features and make their work unnecessarily difficult. In this post, we'll discuss such key features that every API...

READ MORE

Spring Security 5 OAuth 2.0 Login and Signup in stateless RESTful Web Services

Adding social login to a Spring application is now easy with Spring Security 5. It’s well explained in the official documentation, as well as some blogs like this one, which cover the basic requirements. In real world applications though, you’ll have some additional requirements, like registering...

READ MORE

How to get the current user in a Spring Security application

When developing an application, we sometimes need to access the currently logged in user programmatically. In this post, we’ll discuss how to do it when using Spring Security. When someone logs in, Spring Security creates an Authentication object, and stores that in the security context. The...

READ MORE

Spring Framework 5: What’s New For A Common Developer

Spring Framework 5 is coming – with many shiny features – including a new reactive framework. You can find the list of new features at many places in the Internet. Here is a good post on it. So, I gave a closer look to figure out what’s in it for my students. Most of the grand features doesn’t...

READ MORE

Writing Readable Code With Java 8 Method References

Java 8 lambda expressions make our code concise and readable. However, it’s the method references, along with the static and default methods in functional interfaces, which makes our code shine. Let’s take an example. Suppose we have an array of names that we want to sort. The array looks like...

READ MORE

Exception handling in Spring Boot and Spring MVC – Part II

In our last post, we saw that overriding DefaultErrorAttributes and BasicErrorController would be a good way to handle exceptions in a Spring Boot application. But, how exactly to layout a clean exception handling mechanism? As an example, in this post, let’s have a look at how Spring Lemon does...

READ MORE

Exception Handling in Spring Boot and Spring MVC

In a Spring MVC application, there would be multiple ways to handle an exception and send a sensible response to the client. This article explains some of those beautifully. Among those, using a global ControllerAdvice seems most sensible when developing a REST API. However, ControllerAdvices...

READ MORE

Removing null values from JSON responses in Spring Boot

We often return partially filled objects from our controller methods. For example, when returning the current user data, you’d not like the password and other sensitive fields to be returned. You may create a new user object, only fill the fields that you’d like returned, and then return that...

READ MORE

How to avoid double validation in Spring Boot applications

When developing an application, we sometimes reuse the entity classes as command objects. In other words, we use the same entity classes to receive user inputs. See this class for example: @Entity public class Employee { @Id private Long id; @Size(min=1, max=50) ...

READ MORE

Spring Security – Securing URLs By HTTP Method

A common way to restrict access to URLs when using Spring Security is to configure mvcMatchers (or the old antMatchers). For example, say you have an e-commerce application with the products visible at the URL http://www.example.com/products/{id}, which should be accessible to everyone. To...

READ MORE