File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Spring AOP program not running as expected" Watch "Spring AOP program not running as expected" New topic
Author

Spring AOP program not running as expected

rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115
Hi,

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
Author
Rancher

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: http://aspose.com/file-tools
 
subject: Spring AOP program not running as expected
 
Similar Threads
Spring MVC AOP Logger
Hello world spring aop
Spring AOP question
Simple AOP not working
Example problem from Spring in Action AOP