• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Wierd Case with Spring AOP

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
srinivas muni
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic