Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Method not being intercepted

  1. #1
    Join Date
    Sep 2006
    Posts
    115

    Default 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 at 03:34 PM.
    Alex Marshall

  2. #2
    Join Date
    Mar 2007
    Posts
    515

    Default

    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.

  3. #3
    Join Date
    Sep 2006
    Posts
    115

    Default

    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.
    Alex Marshall

  4. #4
    Join Date
    Mar 2007
    Posts
    515

    Default

    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 ?

  5. #5
    Join Date
    Sep 2006
    Posts
    115

    Default

    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.
    Alex Marshall

  6. #6
    Join Date
    Sep 2006
    Posts
    115

    Default

    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.
    Attached Files Attached Files
    Alex Marshall

  7. #7
    Join Date
    Jul 2007
    Posts
    25

    Default

    Quote 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>

  8. #8
    Join Date
    Mar 2007
    Posts
    515

    Default

    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.

  9. #9
    Join Date
    Sep 2006
    Posts
    115

    Default

    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
    Alex Marshall

  10. #10
    Join Date
    Mar 2007
    Posts
    515

    Default

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •