Announcement Announcement Module
Collapse
No announcement yet.
Problem injecting Java 5 Generics Map Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem injecting Java 5 Generics Map

    My implementation contains the following (SettingNameMapper is a Java 5 enum):
    Code:
       ...
       private Map<SettingNameMapper, Pattern> excludeRegex;
       ...
       public void setExcludeRegex( final Map<SettingNameMapper, Pattern> excludeRegex )
       {
          this.excludeRegex =
             new HashMap<SettingNameMapper, Pattern>( includeRegex );
       }
    
       public Map<SettingNameMapper, Pattern> getExcludeRegex()
       {
          return this.excludeRegex;
       }
       ...
    The appContext snippet:
    Code:
                                    ...
                                    <property name="excludeRegex">
                                        <map>
                                            <!-- Foo is a valid SettingNameMapper -->
                                            <entry key="Foo">
                                                <bean
                                                    class="java.util.regex.Pattern"
                                                    factory-method="compile">
                                                    <constructor-arg>
                                                        <value>ABC</value>
                                                    </constructor-arg>
                                                </bean>
                                            </entry>
                                        </map>
                                    </property>
                                    ...
    The error:
    Code:
        ...
        [junit] Caused by: PropertyAccessExceptionsException (1 errors)
        [junit] org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.util.LinkedHashMap] to required type [java.util.Map] for property 'excludeRegex'; nested exception is java.lang.IllegalArgumentException: No matching editors or conversion strategy found
        [junit] Caused by: java.lang.IllegalArgumentException: No matching editors or conversion strategy found
        [junit]     at org.springframework.beans.PropertyTypeConverter.convertIfNecessary
    (PropertyTypeConverter.java:209)
        [junit]     at org.springframework.beans.PropertyTypeConverter.convertIfNecessary
    (PropertyTypeConverter.java:93)
        [junit]     at org.springframework.beans.PropertyTypeConverter.convertToTypedMap(PropertyTypeConverter.java:326)
        [junit]     at org.springframework.beans.PropertyTypeConverter.convertIfNecessary(PropertyTypeConverter.java:190)
        [junit]     at org.springframework.beans.PropertyTypeConverter.convertIfNecessary(PropertyTypeConverter.java:108)
        [junit]     at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:723)
        [junit]     at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:575)
        [junit]     at org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(AbstractPropertyAccessor.java:49)
        [junit]     at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:68)
        [junit]     at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
        [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:816)
        [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:592)
        [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:392)
        [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBeanDefinition(BeanDefinitionValueResolver.java:174)
        [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105)
        [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:274)
        [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:126)
        [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:274)
        [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:126)
        [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:274)
        [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:126)
        [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:801)
        [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:592)
        [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:392)
        [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:240)
        [junit]     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:132)
        [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:237)
        [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:153)
        [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:225)
        [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:114)
        [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveManagedMap(BeanDefinitionValueResolver.java:274)
        [junit]     at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:126)
        [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:801)
        [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:592)
        [junit]     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:392)
        [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:240)
        [junit]     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:132)
        [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:237)
        [junit]     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:153)
        [junit]     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:254)
        [junit]     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:337)
        [junit]     at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
        [junit]     at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
        ...
    Just for kickes, I changed my getter/setting from Map<> to LinkedHashMap<>, but still got the following:
    Code:
        [junit] Caused by: PropertyAccessExceptionsException (1 errors)
        [junit] org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.util.LinkedHashMap] to required type [java.util.LinkedHashMap] for property 'excludeRegex'; nested exception is java.lang.IllegalArgumentException:
     No matching editors or conversion strategy found
        [junit] Caused by: java.lang.IllegalArgumentException: No matching editors or conversion strategy found
        [junit]     at org.springframework.beans.PropertyTypeConverter.convertIfNecessary(PropertyTypeConverter.java:209)
        [junit]     at org.springframework.beans.PropertyTypeConverter.convertIfNecessary(PropertyTypeConverter.java:93)
        [junit]     at org.springframework.beans.PropertyTypeConverter.convertToTypedMap(PropertyTypeConverter.java:326)
        [junit]     at org.springframework.beans.PropertyTypeConverter.convertIfNecessary(PropertyTypeConverter.java:190)
        [junit]     at org.springframework.beans.PropertyTypeConverter.convertIfNecessary(PropertyTypeConverter.java:108)
        [junit]     at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:723)
        [junit]     at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:575)
        [junit]     at org.springframework.beans.AbstractPropertyAccessor.setPropertyValue(AbstractPropertyAccessor.java:49)
        [junit]     at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:68)
        [junit]     at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:57)
        ...
    What am I doing wrong?

  • #2
    Nevermind...

    The error message wasn't very helpful, but it turned out to be "user error". Turns out "Foo" was not a valid enum; "FOO" was. So, the problem was that I was attempting to inject Map<String, Pattern> instead of Map<SettingNameMapper, Pattern>. Once I realized that, it worked like a charm.

    Comment

    Working...
    X