I am using Spring AOP for logging. I am unable to find what is wrong in my code. With Spring AOP and without AOP it gives different output. Any help or comments is really appriciated . Below is the code and configurations
Here when I run the above code testdelegate object is null with AOP ( TestController.java line 23 check : if(d == null ) )
When remove the AOP (by commenting the advice and pointcut ) I can see the normal behavior.
Please let me know Where I am doing Wrong. I already spent few days on this but couldnt figured out the problem
( Sorry for posting the entire code but I thought that will give some clear picture)
Had a glance on your code, I have noticed two things which might help.
1. below code is present in duplicate in logging-configuration.xml and dispatcher-servlet.xml . I would suggest to keep all configuration in dispatcher-servlet.xml only.
2. Add the log4j configuration in your application and enable the debug logging for spring framework. This will some more information on the sequence how your objects are initialized.
Now, coming back to your problem I suspect it is caused due to duplicate entry (as mentioned in point 1) in the configuration file. When the configuration from Logging-configuration.xml loaded ang executed the annotation driven tag is not there. That probably would have caused TestFacade object coming as null. You can also try the below option which will cause the failure if your object is not initialized properly.
Joined: Oct 04, 2010
Thanks For your reply.
Finally I found out the root cause .. For the advice, return type is void . I need to change that to Object and return the Object from joinPoint.proceed();
As you suggested , I will use log4j configuration.
But the other point you made about context:component-scan , I read somewhere(in forums) that it should be specified in aop configuration also ( in this case logging-configuration.xml).
can you provide some more details on that ( Right now it is working fine )