From the course: Java EE: Design Patterns and Architecture
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
AOP: Implement the Interceptor pattern
From the course: Java EE: Design Patterns and Architecture
AOP: Implement the Interceptor pattern
- [Instructor] First I need to create a class that will contain all the cross-cutting logic and annotate it interceptor. So I'm going to create a class. I'm going to call it logger interceptor. So let's call this Loggerinterceptor and I need to annotate it Interceptor, like so. I also need to bind it to an interceptor binding. So I'll add the transactional annotation to the class. Now to the method logic. This must be annotated AroundInvoke and have the right signature, which is that it takes an instance of Invoke context. So I'm going to go up here, and just start creating my method. I'm going to start with the annotation, and call it AroundInvoke, and I'm going to start my method, and it can be a private method. I'm going to return object *and it call my method, doMethod. Logging, and the parameter of course as we know, must be InvocationContext, I'm just going to call this IC. Now, within the method I can write the logic that I want to be executed before each method. And what I…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.