File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Aspect Oriented Programming and the fly likes Wierd Case with Spring AOP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Aspect Oriented Programming
Bookmark "Wierd Case with Spring AOP " Watch "Wierd Case with Spring AOP " New topic

Wierd Case with Spring AOP

srinivas muni

Joined: Oct 04, 2010
Posts: 15
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 ( 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)
Manish Sridharan
Ranch Hand

Joined: Jul 19, 2005
Posts: 65
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.


Manish S.
srinivas muni

Joined: Oct 04, 2010
Posts: 15
Hi Manish,
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 )

I agree. Here's the link:
subject: Wierd Case with Spring AOP
It's not a secret anymore!