Announcement Announcement Module
No announcement yet.
schema aop spring 2 struts actions Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • schema aop spring 2 struts actions

    I am trying to create an aspect that can be cut across my spring loaded struts actions. My struts actions work in spring, but my aop logging example does not.

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation="">
    <!-- Spring integration -->
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>

    <!-- Spring integration end-->


    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "">

    <!-- Data Sources -->

    <!-- Form Beans -->
    <form-bean name="form" type="example1.forms.Form"></form-bean>
    <form-bean name="form2" type="example1.forms.Form2"></form-bean>

    <!-- Global Exceptions -->

    <!-- Global Forwards -->

    <!-- Action Mappings -->
    <action path="/action1" type="org.springframework.web.struts.DelegatingAct ionProxy"
    name="form" scope="request" input="/input.jsp">
    <forward name="success" path="/output.jsp"></forward>
    <forward name="failure" path="/input.jsp"></forward>
    <action path="/action2" type="org.springframework.web.struts.DelegatingAct ionProxy"
    scope="request" input="/output.jsp" name="form2">
    <forward name="success" path="/final.jsp"></forward>
    <forward name="failure" path="/output.jsp"></forward>

    <!-- Message Resources -->
    parameter="example1.resources.ApplicationResources " />

    <plug-in className="org.apache.struts.validator.ValidatorPl ugIn">
    <set-property property="pathnames"
    value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />

    <!-- Spring stuff -->

    className="org.springframework.web.struts.ContextL oaderPlugIn">
    <set-property property="csntextConfigLocation"
    value="/WEB-INF/action-servlet.xml,/WEB-INF/applicationContext-web.xml" />
    <!-- End of Spring Stuff -->


    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns=""
    xsi:schemaLocation=" ">

    <aop:config proxy-target-class="true">
    <aop:aspect ref="logging">
    <aopointcut id="test1"
    expression="execution(* example1.actions.*.*(..))" />
    <aop:before pointcut-ref="test1" method="logBefore" />
    <aop:after-returning pointcut-ref="test1" method="logAfter" />

    <bean id="logging" class="example1.logging.LoggingExample" />


    package example1.logging;

    public class LoggingExample {

    public void logBefore () {
    System.out.println("before an action");

    public void logAfter () {
    System.out.println("After an action");


    <?xml version="1.0" encoding="UTF-8"?>


    <bean name="/action1" class="example1.actions.Action1Action"></bean>
    <bean name="/action2" class="example1.actions.Action2Action"></bean>


    Any assistance would be appreciated.


  • #2
    It's the same issue as in this thread ?

    Also, is much more easier to follow if you put your code inside [ CODE][ /CODE] tags.


    • #3

      If you mean I should use

      <aop:config proxy-target-class="true">
      then well, I've already tried that.

      It is similar to the issue posted by Javier Rivas except I am using xml aop config rather than aspectj, I'm not getting an error message, and It's not working.



      • #4
        I tried to do what you're are doing and it didn't work either, and as I didnt have much more time I gave up.

        Although I think I was very to close to get it working when I defined the action beans as AutoproxyCreators in the Spring applicationContext file.

        Take a look at Section 7.9. ot the Reference Documentation:"Using the "autoproxy" facility", I might help you.

        And please, If you get it working post it. I'll try to do some more work this weekend, and if I came up with a solution Ill let you know.

        Regards, Javier Rivas.


        • #5
          still trying


          I'm still working on this. I'm trying to get it all done through XML although that is seeming much less likely. I am personally not pressed for time on a solution. I am attempting to write a tutorial on how to use the new features.



          • #6
            solved...I think


            It looks to me like action-servlet.xml is loaded into a different container than application-context*.xml. When I moved my aop definitions over to action-servlet.xml, they worked just fine.



            • #7
              Hi Mike,

              Nice one, Ill try that this weekend.


              • #8
                I dont get it working

                Mike, I tried to work out your example doing what you said, but still nothing.

                I agree with you that the action-servlet.xml is loaded into a different container than application-context*.xml., because when I get the Action bean (struts one) from the factory bean in the application-context, the advice is called, and the AOP works as it has to.

                However, when struts is controlling the actions, the AOP advices arent called.

                I have been doing some research and I think that the final classes cant be used with AOP, because as far as I know the CGLIB cant proxy them.
                I dont know, the more I read about the topic, the more confused I am.

                7.5.5. Proxying classes
                CGLIB proxying should generally be transparent to users. However, there are some issues to consider:
                * Final methods can't be advised, as they can't be overridden.

                But on the other hand, as I said, I think that the problem is in which context the beans are loaded, although, putting altogether in the action-servlet.xml didnt work for me.

                Could you post your whole example, so I can see if I am missing something?
                Last edited by Javier Rivas; May 12th, 2007, 09:02 AM.


                • #9

                  Mike, Ive just posted a new thread

                  please take a look

                  P.D. What is that tutorial you're trying to write? Is it an open source tutorial? Well, if you need some help, I wouldnt mind collaborating with you.

                  Regards, Javier


                  • #10


                    I am writing the tutorial for my client with Rational Application Developer 7 as the IDE. I can pass that on to you when I get it done, and you can adapt it as you see fit, or I can post it. I am going to post the contents of my working application on a separate message.



                    • #11
                      files from tutorial

                      Hopefully, the attachment will have what you need Javier.



                      • #12
                        I am trying to do the same thing but with no luck.

                        Here's my thread:

                        I'm basically doing the same thing but it's not working for me.

                        One thing the example posted above is doing differently is repeating the aspect configuration and advice bean in both the struts-config.xml and the applicationContext-web.xml. Not only is it repeated in both but both are loaded in the struts-config.xml plugin part - that I don't understand at all. Why repeat it and why load both ????

                        This is in the struts-config.xml in the attachment from the post above:
                        		<set-property property="csntextConfigLocation"
                        			value="/WEB-INF/action-servlet.xml,/WEB-INF/applicationContext-web.xml" />
                        Note how we're loading both - I don't get it.
                        Last edited by LordHalbert; Sep 28th, 2007, 06:23 PM.