Announcement Announcement Module
Collapse
No announcement yet.
Declarative Transaction Issues With Proxies? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Declarative Transaction Issues With Proxies?

    Simple declarative transaction setup

    Code:
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        	p:dataSource-ref="dataSource"/>
    </bean>
      	
    <tx:advice id="txAdvice" transaction-manager="txManager">
        	<tx:attributes>
    	      	<tx:method name="*" propagation="REQUIRED"/>
        	</tx:attributes>
      </tx:advice>
      	
    <aop:config>
        	<aop:pointcut id="serviceOperation" expression="execution(* com.x.*.service..*Service.*(..))"/>
        	<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation"/>
      	</aop:config>
    This setup is not working, i.e. the services are not transaction.

    All service classes are created with BeanNameAutoProxyCreator with several advisors so I am guessing that perhaps the pointcut execution(public * com.x.*.service..*Service.*(..)) is the problem here. Any insight would be appreciated...

  • #2
    Maybe someone can help you if you say in words what are you trying to execute with:
    execution(* com.x.*.service..*Service.*(..))
    maybe try this,
    execution(* com.x.*.service..Service*(..))

    Comment


    • #3
      I would rather suggest
      execution(* com.x..service..*Service.*(..))

      But some examples for what should be matched might indeed be helpful.

      Regards,
      Andreas

      Comment


      • #4
        Thanks guys. The problem is not in the matching, I guess I wasn't clear. I am using AJDT plugin so I have 905 matches for the pointcut, no issues there. The issue is that the services that should be matched by the pointcut are created with org.springframework.aop.framework.autoproxy.BeanNa meAutoProxyCreator (several other advisors) so I just wondering if that may be the issue as to why at runtime my services are not transactional? At runtime then the service become Proxy$1.... so I am just wondering if that is a problem?

        Comment


        • #5
          I would remove the BeanNameAutoProxyCreator and do everything with the aop:config block. That way you only have 1 BeanPostProcessor creating proxies, that can prevent a lot of issues, especially when mixin class/interface proxies or only class proxing (cglib marks classes final so proxy 1 is created whereas the second is not for instance).

          However your pointcuts shouldn't be a problem if you program to interfaces you might need to add the subclass identifier which is a + so instead of

          Code:
          execution(* com.x..service..*Service.*(..))
          use

          Code:
          execution(* com.x..service..*Service+.*(..))

          Comment

          Working...
          X