Announcement Announcement Module
Collapse
No announcement yet.
Method not being intercepted Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Method not being intercepted

    Hello,

    I'm trying to use annotation based AOP to inject security information into my beans before I save them. I have a generic interface BeanDao<BeanType> which all my DAOs extend, and a base implementation using Hibernate (HibernateBeanDaoImpl<BeanType>) from which all my beans extend. The pointcut I'm using is this : "execution(* com.mypackage.BeanDao.save*(..))".

    The problem I'm having is that the "save(BeanType bean)" method gets intercepted, but the "saveAll(Collection<BeanType> collection)" method does not. Can anybody tell me what I might be doing wrong ?

    I'm using @Before advice on the @Pointcut, and I have <aop:aspectj-autoproxy/> declared along with all my @Aspect beans in my context. I'm using a mixture of annotated aspects and ProxyFactoryBean intercepted beans, though none of the latter affect the beans with which I'm having this problem.
    Last edited by alexmarshall; Aug 31st, 2007, 03:34 PM.

  • #2
    There is a JIRA issue related to generics not being properly processed: http://opensource.atlassian.com/proj...rowse/SPR-3556
    Try to test the same advice with the latest nightly build Spring version.

    Comment


    • #3
      Hi Andrei,

      I remember I had a very similar problem a while back that was affected by that very same issue, and I have tried it with the latest spring nightly, however nothing has changed. I've even tried changing my pointcut to "execution(* com.mypackage.BeanDao.*(..))" (all methods, rather than just methods beginning with "save") and the "saveAll" method still does not get intercepted.

      Comment


      • #4
        Just made a test with an method like this: bat(Collection<String> col). I used the latest nightly build and also an older version. The bug described in 3556 JIRA issue is fixed in the new version, but the bat method above works with the new version and the old one, also.
        Is your test different than mine ? Can you post more code details, please ?

        Comment


        • #5
          Hi Andrei,

          I just got back from out of town. It's currently midnight. I'll post more details tomorrow morning once I'm back at my development machine.

          Comment


          • #6
            Hi Andrei,

            I've just written a unit test that proves my case. I wrote two interfaces and corresponding implementations to simulate my current problem with (nearly) identical join points and point cuts to what I'm trying to use in my production system, the only thing that's changing is package and class names. The method with a generic collection fails, whereas if the method is non-generic (ie java 1.4.2 or less) then the interception works just fine. Attached is the source code , application context and unit test to prove it. Please have a look. I believe this relates to SPR-3556. I have tried on both the production Spring 2.0.6 release and the nightly 2.0.7 snapshot from 20070810-71 with the same results.

            Comment


            • #7
              Originally posted by alexmarshall View Post
              Hi Andrei,

              I've just written a unit test that proves my case. I wrote two interfaces and corresponding implementations to simulate my current problem with (nearly) identical join points and point cuts to what I'm trying to use in my production system, the only thing that's changing is package and class names. The method with a generic collection fails, whereas if the method is non-generic (ie java 1.4.2 or less) then the interception works just fine. Attached is the source code , application context and unit test to prove it. Please have a look. I believe this relates to SPR-3556. I have tried on both the production Spring 2.0.6 release and the nightly 2.0.7 snapshot from 20070810-71 with the same results.
              Hi,
              I am having similar problems. Though not with the generics but with the following implementation
              Due to space restraint i am only posting a portion of the config file; Here the advice is not even loaded by the IOC. Meaning to say, if i mistype its name the IOC does not even throw an error.
              <aop:config proxy-target-class="true">

              <aopointcut id="entryPointMethod"
              expression="execution(* biz.dao.PersonDAOImpl.*(..))" />

              <aop:advisor advice-ref="txAdvice"
              pointcut-ref="entryPointMethod" />


              </aop:config>

              <tx:advice id="txAdvice" transaction-manager="txManager">
              <tx:attributes>
              <tx:method name="get*" read-only="true" />
              <tx:method name="check*" rollback-for="RuntimeException" />
              </tx:attributes>
              </tx:advice>


              <bean id="txManager"
              class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
              <property name="dataSource" ref="dataSource" />
              </bean>

              Comment


              • #8
                Sorry for getting back to you so late, Alex. I made another test, this time with an AspectJ project and the same happens in there too. Note that the pointcut works if you change it like this:
                Code:
                execution(* GenericIFace+.save*(..))
                If still having problems, maybe JIRA can be of more help.

                Comment


                • #9
                  The change got my aspects working. You just solved my problem and saved me a bunch of work, so I think I can forgive you. :P

                  Thank you so much Andrei, I really appreciate all the effort

                  Comment


                  • #10
                    I'm glad my suggestion works for you. But, I think I'll create a JIRA issue, since this case should work, in my opinion.

                    Comment


                    • #11
                      I think that's a good idea. If you do create it, please post the link back here and I'll vote and watch for it.

                      Comment


                      • #12
                        http://opensource.atlassian.com/proj...rowse/SPR-3904

                        Comment

                        Working...
                        X