Kotlin SpringMVC HandlerInterceptor – Spring Boot

In the tutorial, JavaSampleApproach will show you how to create a Kotlin SpringMVC HandlerInterceptor that provides a mechanism to intercept requests {preProcessing, postProcessing and afterCompletion} with SpringBoot.

I. Technologies

– Java 1.8
– Maven 3.6.1
– Spring Tool Suite – Version 3.9.0.RELEASE
– Spring Boot – 1.5.9.RELEASE
– Kotlin 1.1.61

II. Goal

We use SpringToolSuite to create a Kotlin SpringBoot project as below structure:

Kotlin SpringMVC HandlerInterceptor - project structure

Use HandlerInterceptor to intercept requests:

With a simple RestAPI:

We make a request http://localhost:8080/hello, see logs:

III. Practice

Step to do:
– Create Kotlin SpringBoot project
– Implement HandlerInterceptor
– Register HandlerInterceptor
– Create Web Controller
– Run & Enjoy result

1. Create Kotlin SpringBoot project

We use SpringToolSuite to create a Kotlin SpringBoot project with dependencies:

2. Implement HandlerInterceptor

3. Register HandlerInterceptor

4. Create Web Controller

5. Run & Enjoy result

Run the project with commandline mvn spring-boot:run.
-> console logs:

IV. Sourcecode


By grokonez | December 8, 2017.

Related Posts

Got Something To Say:

Your email address will not be published. Required fields are marked *