Category: Spring Framework

Create Pointcut using simple name matching

You can create the Pointcut by simply matching the name of the method. We can use the NameMatchMethodPointcut class for this. In this example when you match “drive” for drive() and drive(speed). Spring does not care about the argument We will start withe the class Car

Then you have the CarAdvice class with before […]

Read more

DyanmicMethodMatcherPointcut for creating dynamic pointcut

In Spring Aspect Oriented programming, you can create dynamic pointcut using DyanmicMethodMatcherPointcut class

Read more

Compose two or more pointcuts together

Read more

Run advice on selected method using Advisor and Pointcut

This is the Car bean class which we are going to use in this example. We have two methods drive() and getName() in this class. I need to run advice when drive() method is called. I do not need to run the advice on getName() method is called We can do this using pointcut mechanism […]

Read more

AOP Introduction

There are some terms which you have to be familiar when learning Aspect Oriented Programming with Spring Framework Joinpoints This is a well-defined entry point to your execution of the program. In AOP, you need to insert some additional code at some point. So these entry point can be used to insert those code Advice […]

Read more

Getting started AOP with Spring Framework

We are going to do small program using Spring Framework to study the basics of the Aspect-Oriented Programming In this example I will create simple Java Console application You will need aspectjrt.jar, aspectjweaver.jar and spring-aop.jar file for this application in addition to basic Spring jar file. First you can create the Car bean class


Read more

Spring Bean lifecycle events – Annotation based

You can use spring annotation to implement Spring Bean lifecycle events firing methods. This is JSR-250 life-cycle annotation @PostConstruct and @PreDestroy I have added above two anotation in this Bean class

You can have the following xml file with

To test the above code you use the following main method

You can […]

Read more

Spring Bean lifecycle events – method based

In this method we can define a method as initialization method so that Spring can call that method once setting all properies and checking the dependencies I am creating init() method inside the Car bean

Now you have to add init-method attaribute to the bean tag and set the value as name of the […]

Read more

Interface based method for Lifecycle events in Bean

We will see howe we can use interface to implement the lifecycle events of the bean. You can have two intrfaces. One is InitializingBean and has a method afterPropertiesSet. Other interface is DisposableBean which has the destroy . This method will be fired by Spring when you do not have rerefence to the bean and […]

Read more

Spring Bean Lifecycle

There are two lifecycle events related to Spring Bean. They are post-initialization and pre-destruction Post-initialization happens when Spring finishes setting all the properties of the bean and checking all the dependencies of the bean The pre-desctruction event is fired just before the bean is destroyed by the Spring Container If your Bean has prototype scope […]

Read more