Results 1 to 5 of 5

Thread: AOP Config won't work!

  1. #1
    Join Date
    Nov 2010
    Posts
    3

    Default AOP Config won't work!

    Hi mentors

    I've spent far too long trying to understand why this won't work, so any help is much appreciated. I am trying to log when a transaction starts and when it commits so that it is clearer in my logs. I got the start transaction working but cannot figure out why the commit won't work (commits are happening):

    Code:
        <!-- AOP -->
        <bean id="connectionInterceptor" class="com.xxx.xxx.ConnectionInterceptor"/>
        <aop:config>
            <aop:pointcut id="startTransaction"    expression="execution(* javax.sql.DataSource+.getConnection(..))"/>
            <aop:pointcut id="commitTransaction"   expression="execution(* java.sql.Connection+.commit(..))"/>
    
            <aop:aspect ref="connectionInterceptor">
                <aop:before pointcut-ref="startTransaction"     method="logTransactionStart" />
                <aop:before pointcut-ref="commitTransaction"    method="logTransactionCommit" />
            </aop:aspect>
        </aop:config>
    I don't know if it is significant but I'm also using @Transactional to wrap my code (this too is working fine!).

    Any suggestions - I am on the verge of abandoning this !

    Thanks
    Dave

  2. #2
    Join Date
    Jul 2010
    Location
    Venice, Italy
    Posts
    709

    Default

    Hmmm remember that Spring transactional support works through aop so that may be an issue (especially since if you let Spring handle transaction you shouldn't add logic to them, not even for something apparently harmless like logging)...posting your ConnectionInterceptor could spread more light into this matter.

    PS if you configure log4j to output at debug level for org.springframework, transaction commits and rollbacks handled by Spring @Transactional (as well as sql executed and rollback reasons) are already logged, so maybe what you are trying to achieve yourself might not be needed.

  3. #3
    Join Date
    Nov 2010
    Posts
    3

    Default

    Hey Enrico

    thanks for your reply. After a bit of thinking I've decided that what I was trying to do probably wouldn't have achieved what I was hoping anyway! Still not sure why the commit() wouldn't work but I think you're probably right about Transactional support.

    Never mind, at least I have learned a bit about aop so no time wasted really.

    Cheers
    Dave

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    It has nothing to do with the transactional.. It has to do with the fact spring aop works... (I suggest a read of the aop chapter especial the section explaining proxies!!!).

    Spring only proxies beans it controls, your datasource is probably defined in your xml, the connections aren't! . So the Datasource is proxied your connections aren't... If you want it to work, don't use spring aop, use a fullblown aop solution like aspectj with compile time or loadtime weaving (in this case you probably need loadtime weaving).
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  5. #5
    Join Date
    Nov 2010
    Posts
    3

    Default

    Thanks Marten

    That explains it then. You right that my data source is under Spring control so now I understand why it worked for one thing and not the other. I have so much more to learn!

Posting Permissions

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