Announcement Announcement Module
Collapse
No announcement yet.
AspectJ AOP and Struts Action Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • AspectJ AOP and Struts Action

    I'm trying to create aspect (advice) that will intersect a Struts Action class method. I've tried EVERYTHING and NOTHING works.

    Here's my struts-config.xml fragment:

    Code:
    <struts-config>
    	<action name="doSomethingForm" type="org.springframework.web.struts.DelegatingActionProxy" path="/doSomething" parameter="action" scope="request">		
            ...
    	</action>       
            ...
    	<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn"> 
    		<set-property property="contextConfigLocation" value="/WEB-INF/testAspect.xml" /> 
    	</plug-in>	
    </struts-config>


    And here's my testAspect.xml
    Code:
    <beans ...>
    	<bean id="testAspect" class="com.somecompany.TestAspect"/>		
    	
    	<aop:config proxy-target-class="true">
    		<aop:aspect ref="testAspect">			
    			<aop:pointcut id="someOperation"
    				expression="execution(* com.somecompany.SomeStrutsAction.execute(..))"/>
    			
    			<aop:before pointcut-ref="someOperation"
    				method="doSomething"/>
    			
    		</aop:aspect>
    	</aop:config>	
    	
    	<bean name="/doSomething" scope="prototype" autowire="byName" class="com.somecompany.SomeStrutsAction"/>		
    		
    </beans>
    Here's my Advice code (not much there):
    Code:
    public class TestAspect {
       
       public void doSomething() {
          log.info("Yes, my advice is working !!!!!!");
       }   
    }
    My Advice is not being called - what could be the problem ???

    HELP !!!!

  • #2
    I am very much of a novice with respect to AOP and using Spring to handle Struts, so my comment may be completely irrelevant... The only thing I notice is the
    Code:
    scope="request"
    for your action. Instead I think you what you need is:
    Code:
    scope="prototype"
    With your current setup, I think that each and every request would instantiate a copy of all your actions! On the other hand, by registering a RequestContextListener in your web.xml file, you let Spring's WebApplicationContext instantiate actions if and when they are needed (i.e. as prototypes) by your Struts Controller.

    I hope that's part of the solution to your problem, but it might well be completely incidental...

    Comment


    • #3
      The scope element you mentioned is for the "struts-config.xml" - has nothing to do with spring.

      That's not the problem.

      I've tried so many things that I'm beginning to think it's a bug with Spring itself.

      Comment


      • #4
        Oops, you're right! I shouldn't try to post answers when I'm half asleep!

        Comment


        • #5
          Have you found an answer to your question? I have the exact same problem here and still no clue.

          Comment


          • #6
            Is SomeStrutsAction a Spring bean? Spring AOP applies only to Spring bean. If struts or other framework creates the objects, Spring AOP won't be able to create proxy for those beans. You will need AspectJ weaving to handle those situations. See Spring and AspectJ documentation for more details.

            -Ramnivas

            Comment


            • #7
              Did any body get the solution ??

              Comment

              Working...
              X