Spring MVC + Angular CRUD Example

In this tutorial we will see the integration of AngularJS with Spring MVC. We are going to create CRUD application using Spring REST API on server side and AngularJS is encapsulated within JSP file on client side. Thus the client will communicate with server asynchronously using AngularJS $http service. If you need PHP version https://roytuts.com/angularjs-php-rest-crud-example/ If you need Codeigniter version…

Spring Asynchronous Execution using @Async

Spring Async In this tutorial I will discuss about the asynchronous execution support in Spring using the @Async annotation. There are cases where Spring framework’s @Async is necessary to execute piece of code asynchronous. An example would be while sending a (JMS) message from one system to another system. The advantage is that the user does not have to wait…

@PreAuthorize Annotation – hasRole Example In Spring Security

Spring Security Has-Role In this tutorial I will show you an example on @PreAuthorize annotation – hasRole() example in Spring Security. @PreAuthorize is the most useful annotation that decides whether a method can actually be invoked or not based on user’s role. hasRole() method returns true if the current principal has the specified role. By default if the supplied role…

Spring Service Layer Bean Validation

Introduction In my previous tutorial I have shown how to validate input data coming from client or end user to Spring REST Controller. Now in this tutorial I will show you how to validate data in Spring Service Layer. The reason behind validating input data in Service Layer is, input data from client may not always pass through the REST…

Spring REST Optional Path Variable Example

Optional Path Variable In this tutorial I will show you how to work with Spring framework’s optional path variable (PathVariable) in REST services. Here I will use Java 8’s java.util.Optional or using attribute required=false and at least Spring Boot 2.1.4 to support optional PathVariable. The optional variable can be found in the URI resource path of the URL.

Validate input data in REST service

Introduction In this tutorial I will show you how you can validate your input data while working with REST service. Generally you need to validate the input data coming from end users because users may give anything as an input but your service side code should not accept anything as an input for the defined field. Prerequisites Please go through…

Documenting Spring REST API with Swagger 2

When creating a REST API, good documentation is instrumental. But developers do not have any option using JSR-339 to generate any documentation on all these APIs so other developers could quickly understand how to use them. For sure, it would be just awesome to generate verbose and easy to follow documentation from source code, and but the help is coming in…

Spring Boot Security Pre-authentication Example

Spring Security Pre Authentication Here you will see an example on Spring Security Pre-authentication. There are situations where you want to use Spring Security for authorization, but the user has already been reliably authenticated by some external system prior to accessing the application. In such situations where Spring Security Pre-authentication comes into picture I refer to these situations as “pre-authenticated”…