Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring AOP program not running as expected

 
rakesh kadulkar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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();
}


}
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ;)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic