• 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

Integrating Spring AOP with existing Struts2 Application

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

We are trying to integrate Spring AOP in to our struts2 application for logging and authentication. We tried a sample struts2 app and integrated aop successfully. But when we integrated in to our actual application, we are facing some issues. It is not throwing any exceptions nor the advice is called. Looks like the proxies are not created using cglib (found using the StackTraceElement of RuntimeException).

web.xml



applicationContext.xml



strusts.xml



Aspect Class


Would be great, if anyone could help us fix this issue.

Thanks in advance.
 
ah habibi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Upon further investigation, found that, the instance for the next class, is being created dynamically using classObj.newInstance().

Is this the reason for the proxy class not being created ? Is there a way to overcome this ?

Help will be much appreciated.

Thanks in advance.
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Spring doesn't weave aspects into classes that are not loaded by Spring. The way I have done something like this before is that instead of putting all the code in Struts actions, divide the code into Action and services; the services should be declared as spring loaded beans; the action classes should get the service objects from spring and call them. Spring will create proxies of your service classes that wrap your aspects, adn all calls from action to services will go through the proxies.
 
ah habibi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.

We have our application as you mentioned like Action + services. I have tried to load the services from spring, but that is not happening. When the server starts, all the beans mentioned in the applicationContext.xml were created by spring, but when the actual request comes, the classes are loaded/objects created by struts/xwork. Thats when we digged deep and found that classObj.newInstance() method call.

Can we overcome this ?

 
ah habibi
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have updated our code to get the beans from the ApplciationContext and if the bean is not found in the bean factory, we use the obj.newInstance(), in the catch block, to create objects on the runtime. This resolved the issue and the advice is applied without any issues.


reply
    Bookmark Topic Watch Topic
  • New Topic