Meaningless Drivel is fun!*
The moose likes Spring and the fly likes Integrating Spring AOP with existing Struts2 Application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "Integrating Spring AOP with existing Struts2 Application" Watch "Integrating Spring AOP with existing Struts2 Application" New topic
Forums: Spring Aspect Oriented Programming
Author

Integrating Spring AOP with existing Struts2 Application

ah habibi
Greenhorn

Joined: Dec 02, 2013
Posts: 6
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

Joined: Dec 02, 2013
Posts: 6
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
Bartender

Joined: Jan 17, 2008
Posts: 2273
    
  28

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

Joined: Dec 02, 2013
Posts: 6
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

Joined: Dec 02, 2013
Posts: 6
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.


 
wood burning stoves
 
subject: Integrating Spring AOP with existing Struts2 Application
 
Similar Threads
Wierd Case with Spring AOP
Spring 3 + Spring Security 3 + Struts2 + Hibernate 3
LazyInitializationException [spring + struts2]
Integrating Spring AOP with existing Struts2 application
spring hibernate and struts2 problem