Reading Notes for Spring 3 Core Components Tutorial Part IV (Chapter 17 to Chapter 19)
This is a reading note from Spring Framework 3.1 Tutorial pdf, created by tutorialspoint. This pdf contains information for Spring 3 Core Basics, which is very useful for understanding defination and practive in Spring programming.
Note: All tips that is written by book will has a sign near it. All code example in this post comes from book.
This note includes Chapter 17 to Chapter 19 in tutorial.
Chapter 17: Event Handling in Spring
In Spring, the ApplicatonContext publishes certain types of events when loading the beans.
ApplicationEvent class and ApplicationListener interface is used in ApplicationContext to deal with event handling.
If a bean implements ApplicationListener, then every time ApplicatioContext publish an ApplicationEvent, this bean will be notified. Spring Events are following:
Spring event handling is single-threaded. So if an event is published, unless all receivers get the message, the processes are blocked and the flow will not continue.
A bean can implement the ApplicationListener interface to listen a event. ApplicationListener only has one method, which is onApplicationEvent().
Aspect Oriented Programming (AOP) entails breaking down program logic into distinct parts called concerns,or crossing-cutting concerns. These concerns are conceptually separate from the application’s bussiness logic.
Spring AOP modules provides interceptors to intercept an application. For example. when a method is executed, you can add extra functionality before or after the method execution.
Type of Advice
XML Schema Based Aspect Implementation
Use regular classes along with xml based configuration
xml needs to be configured:
You need to add AspectJ libraries to your CLASSPATH.
The way to declare an aspect is using <aop:aspect> element and usint ref attribute to find bean:
The way to declare an pointcut is to use <aop:pointcut> elements. pointcut is sued to determine the method(i.e. join point) to be excuted in advices: