Announcement Announcement Module
Collapse
No announcement yet.
Spring Context (XML): Transaction Advice with Method Parameters possible? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Context (XML): Transaction Advice with Method Parameters possible?

    Hi All,

    I cannot find a way to configure Spring context XML doing declarative transactions just like what you can do in EJB deployment descriptors like this:

    Code:
    <assembly-descriptor>
        <container-transaction>
            <method>
                <ejb-name>CreditService</ejb-name>
                <method-name>setLimit</method-name>
                <method-params>
                    <method-param>int</method-param>
                </method-params>
            </method>
            <trans-attribute>Required</trans-attribute>
        </container-transaction>
    ...
    </assembly-descriptor>
    You can define chosen transaction attribute for the method "setLimit" with an integer as parameter.

    In Spring XML I cannot tell Spring to do the same thing. I just can configure the method name but without parameters. Example:

    Code:
    <tx:advice id="txAdvice" transaction-manager="txManager">
         <tx:attributes>
          <!-- No parameters possible! -->
          <tx:method name="setLimit" read-only="false" propagation="REQUIRED"/>
        </tx:attributes>
      </tx:advice>
    
      <aop:config>
        <aop:pointcut id="creditServiceOperations" expression="execution(* x.y.service.CreditServiceImpl.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="creditServiceOperations"/>
      </aop:config>
    How can I do the same thing just like in the EJB descriptor above?

    One alternative is to define a pointcut for each service operation but if you have 50 service operations it will be quite heavy since you will get 50 pointcuts, 50 advisors and 50 advices... I also cannot use @Transactional annotation since I generate the Spring XML automatically (I'm doing MDA). So I need to use the Spring context XML file...

    Any help is really appreciated!

    Thanks,
    Lofi.

  • #2
    Hello

    I am confused with your case

    You can define chosen transaction attribute for the method "setLimit" with an integer as parameter. In Spring XML I cannot tell Spring to do the same thing.
    Did you research in Spring documentation?

    One alternative is to define a pointcut for each service operation but if you have 50 service operations it will be quite heavy since you will get 50 pointcuts, 50 advisors and 50 advices
    such for each should avoid and resolved with a well written pattern for your pointcut's expression attribute which should intercept a lot of services and not only one

    Comment


    • #3
      Thanks for your fast response!

      Originally posted by dr_pompeii View Post
      Did you research in Spring documentation?

      such for each should avoid and resolved with a well written pattern for your pointcut's expression attribute which should intercept a lot of services and not only one
      This would be not a problem if you want to create the expression manually by hand. My problem is that I generate the whole XML file with a generator automatically so I need a mechanism where I can simply generate those attributes, such as:

      "get all the Service Operations -> iterate them -> put the correct TX attribute for the actual Operation -> done".

      It would be a lot more complicated to try to generate a "well-written" expression...

      So a possibility just like in EJB descriptor would be great.

      Thanks,
      Lofi.
      http://lofidewanto.blogspot.com

      Comment

      Working...
      X