Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Integrating Spring AOP with existing Struts2 Application

 
ah habibi
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Jayesh A Lalwani
Rancher
Pie
Posts: 2756
32
Eclipse IDE Spring Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic