This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Spring and the fly likes Spring AOP program not running as expected Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring AOP program not running as expected" Watch "Spring AOP program not running as expected" New topic

Spring AOP program not running as expected

rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115

I am referring to Spring In Action and I am at the end of the first chapter i.e. Springing into action.

I am trting to run the demo given for AOP introduction.

I am giving the code for all here including my xml file.

This is my employee class

This is my MyLogger class

This is the configuration file

What I expected is whenever I call embarkObQuest() method on the employee object it will first call the before() method of MyLogger and then the embarkOnquest() method execution and after that after() method on MyLogger object.
But when I run the program it shows only the output from embarkOnQuest() method and not from before() and after) method.

What may be wrong?

Here is the client code.

public class Main {

* @param args the command line arguments
public static void main(String[] args) {
// TODO code application logic here
BeanFactory factory = new XmlBeanFactory(new FileSystemResource("./config/employee.xml.xml"));
Employee emp = (Employee)factory.getBean("emp");
Object obj = emp.embarkOnQuest();


Rakesh Kadulkar
David Newton

Joined: Sep 29, 2008
Posts: 12617

I'm not sure that using a plain XmlBeanFactory works for this; I'd use an ApplicationContext (a ClassPathXmlApplicationContext, in this case) to make sure pre- and post-processors are registered.I'd also recommend using classpath-based configuration files (and avoiding filenames with doubled extensions ;)
I agree. Here's the link:
subject: Spring AOP program not running as expected
Similar Threads
Simple AOP not working
Hello world spring aop
Spring AOP question
Spring MVC AOP Logger
Example problem from Spring in Action AOP