Some main program calls the method doSomeOperation which in turn calls the other methods in the class based on business rule. I have a situation where I have to populate some stats after some of the methods in this class is invoked.
For example, after calling doSomeOperation which in turn calls say doOps1, populate some stats table on the database indicating how many records were inserted/updated/deleted etc in specific table and how much time it took etc by doOps1 method. I am trying to use Spring AOP for this purpose. However the issue that I am facing is that the intended code is not getting invoked.
The Spring bean definition
On running the main program, I am getting the output (and it is not calling profile1 rom the Aspect class - BusinessProfiler). however if I directly call the doOps1 from main class then the aspect method gets invoked. I would like to know if aspect is supposed to work if only called from the main method and not otherwise.
The problem is that by default Spring uses interface based proxies. Meaning to call the method through the proxy you must do it through the interface. You have a self call that is not done through the proxy but on a reference of this
You could try proxying the target class by adding that option to your <aop:aspectj-autoproxy /> tag
or you could also look at different weaving options. There is a blog I found that talks about this a little bit
I had my doubts the proxy target class would work, but you did not experiment with other weaving options.
Now if you expose doOps1 via the interface and access it through that interface it will work
If you want your original code to work as you posted it originally with the self call, then weave in your aspects at compile time, then it will work. This can be done with the maven plugin see the below POM fragment for an example.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com