Results 1 to 6 of 6

Thread: Help! How to define MethodMapTransactionAttributeSource?

  1. #1
    Join Date
    Nov 2004
    Posts
    4

    Default 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. #2
    Join Date
    Nov 2004
    Posts
    4

    Default

    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.

  3. #3
    Join Date
    Nov 2004
    Posts
    4

    Default

    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.

  4. #4
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    (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.
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  5. #5
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    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?
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  6. #6
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    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...
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

Similar Threads

  1. Replies: 2
    Last Post: Aug 3rd, 2005, 04:34 AM
  2. How to define a default language??
    By falaserioaih in forum Web
    Replies: 1
    Last Post: Jul 8th, 2005, 05:33 AM
  3. How to define a map of Long values
    By roshang in forum Container
    Replies: 10
    Last Post: May 16th, 2005, 06:58 PM
  4. Replies: 1
    Last Post: Jan 25th, 2005, 01:24 AM
  5. Get Bean Define from DataBase?
    By waspxyz in forum Container
    Replies: 3
    Last Post: Sep 15th, 2004, 08:13 AM

Posting Permissions

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