my dog learned polymorphism*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Aspect Oriented Programming
Bookmark "Wierd Case with Spring AOP " Watch "Wierd Case with Spring AOP " New topic
Author

Wierd Case with Spring AOP

srinivas muni
Greenhorn

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

web.xml


dispatcher-servlet.xml

logging-configuration.xml


TestController.java

TestFacade.java


TestDelegat.java


AOPLogger.java


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)
Thanks
Manish Sridharan
Ranch Hand

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


Thanks,


Manish S.
srinivas muni
Greenhorn

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 )

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Wierd Case with Spring AOP