Announcement Announcement Module
Collapse
No announcement yet.
Help! How to define MethodMapTransactionAttributeSource? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help! How to define MethodMapTransactionAttributeSource?

    :shock:
    The MethodMapTransactionAttributeSource in spring version 1.1.2 needs methodMap property being set.
    The set method of the property requires a Map, what's wrong with my bean definition below.
    It saids can't convert java.util.Property to java.util.HashMap, but why hashmap, the setter method requires only java.util.Map. Is this a bug?

    Code:
       <bean id="classMethodMatchAttributeSource"
            class="org.springframework.transaction.interceptor.MethodMapTransactionAttributeSource">
            <property name="methodMap">
                <props>
                    <prop key="com.erry.dx.security.DXSecurityManager.createNewRSAKeyPair">PROPAGATION_REQUIRED,-Exception</prop>
                    <prop key="com.erry.dx.security.DXSecurityManager.importRSAKeyPair">PROPAGATION_REQUIRED,-Exception</prop>
                    <prop key="com.erry.dx.security.DXSecurityManager.*">PROPAGATION_SUPPORTS</prop>
                    <prop key="com.erry.dx.monitoring.DxRuntimeMonitor.registerNewWorkGroup">PROPAGATION_REQUIRED,readOnly</prop>
                    <prop key="com.erry.dx.monitoring.DxRuntimeMonitor.*">PROPAGATION_SUPPORTS</prop>
                    <prop key="com.erry.dx.core.DxWorkManager.sendDataElements">PROPAGATION_NEVER</prop>
                    <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>
                </props>
            </property>
        </bean>
    
    I have tried to use this either. But still class cast exception occurs.
    Says that error trying to convert a LinkedMap to HashMap.
    <map>
    <entry>...</entry>
    
    </map>
    Can anybody tell me how to configure this bean in Spring 1.1.2?

  • #2
    The error are like this, which seems rediculous.

    org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.util.LinkedHashMap] to required type [java.util.Map] for property 'methodMap'; nested exception is java.lang.ClassCastException: null

    But the LinkedHashMap is a direct subclass of java.util.HashMap.
    This error message makes no sence.

    Comment


    • #3
      I have check the source code, the class cast exception occured when Spring tried to convert my string value to TransactionAttribute.
      Can anyone tell me how to correctly define the MethodMapTransactionAttributeSource, thank you very much.

      Comment


      • #4
        (Edited later, no it's not! Please see later posts): Your definition looks ok as far as I can tell at a quick glance. If you can include a stack trace of the error, that would be good, so I can see where you are getting the exception.

        Here'e a post where I talk a bit about this:
        http://www.newsarch.com/archive/mail.../msg02597.html

        As I mention in the post above, there is a MethodMapTransactionAttributeSource converting property editor that will be picked up automatically (since it is sitting in the same package as the MethodMapTransactionAttributeSource). So if you need to pass a MethodMaptransactionAttributeSource to a property that needs one, it's usually easier to just declare it as a string value, with one line per entry as in my example in the post.

        Comment


        • #5
          Colin,
          I saw your post before and am really stuck!!!
          Code:
            <bean id="myMethodMapTransactionAttributeSource" 
               class="org.springframework.transaction.interceptor.MethodMapTransactionAttributeSource">
              <property name="transactionAttributes">
                <props>
                  <prop key="com.whatever.packagex.MyClass.insert*">PROPAGATION_REQUIRED,-MyCheckedException</prop>
                  <prop key="org.something.packagey.AnotherClass.insert*">PROPAGATION_REQUIRED</prop>
                  <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
                </props>
              </property>
            </bean>
          I double checked MethodMapTransactionAttributeSource source and reviewed old versions in CVS, MethodMapTransactionAttributeSource never had a property with name transactionAttributes!!! Am I wrong?

          Comment


          • #6
            No, you're right. I was doing a bit too much cutting and pasting in that post. Don't know what I was smoking... The main point I was trying to make in that post (and here) is that you generally do not have to actually create a MethodMapTransactionAttributeSource, as anything that needs one can be fed a String which will be converted by the property editor.

            Now as for Siverhoof's problem, it's actually very simple, on reflection. The setMethodMap method is taking a map of method name keys (strings) to TransactionAttribute objects. But Siverhoof was feeding in strings for the latter. Rather than going to the pain of creating real TransactionAttribute objects for the map values though, I would just rely on the automatic propertyeditor to build my entier MethodMapTransactionalAttributeSource for me...

            Comment

            Working...
            X