Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7084147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:15:55+00:00 2026-05-28T07:15:55+00:00

I have created a StringToMapConverter for converting string in predefined format to a Map

  • 0

I have created a StringToMapConverter for converting string in predefined format to a Map of key-value pairs.The key can be Enum type also.

However in the converter I required the reference to org.springframework.core.convert.ConversionService instance for converting string to enum.Thus in my myapp-servlet.xml context I tried registering like:

<bean id="stringToMapConverter" class="com.myapp.util.StringToMapConverter"/>

<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean">
        <property name="converters">
            <bean ref="stringToMapConverter" />
        </property>
</bean>

This ended me up in circular dependency error like “conversionService: FactoryBean which is currently in creation returned null from getObject”.

Thus I tried using a class ConverterConfig annotated with @Configuration (code I have provided below) which resolved this circular dependency error but now I am facing the following error.

org.springframework.validation.BindException: org.springframework.validation.BeanPropertyBindingResult: 1 errors
Field error in object 'searchResultsRefiner' on field 'filtersMap': rejected value []; codes [typeMismatch.searchResultsRefiner.filtersMap,typeMismatch.filtersMap,typeMismatch.java.util.Map,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [searchResultsRefiner.filtersMap,filtersMap]; arguments []; default message [filtersMap]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.util.Map' for property 'filtersMap'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [java.util.Map] for property 'filtersMap': no matching editors or conversion strategy found]
    at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:810)
    at or

I debugged my application and found that the converter was successfully getting added to the registery.But still the framework is unable to find it at time when data is required to convert from java.lang.String to java.util.Map.

Below mentioned is the code I have written:

SearchResultsRefiner.java

 public class SearchResultsRefiner {

    private Map<SearchRefineFilter, String> filtersMap;

    public SearchResultsRefiner() {}


    public Map<SearchRefineFilter, String> getFiltersMap() {
        return filtersMap;
    }

    public void setFiltersMap(Map<SearchRefineFilter, String> filtersMap) {
        this.filtersMap = filtersMap;
    }

    }

ConverterConfig.java

  import java.util.Collections;

    @Configuration
    public class ConverterConfig {

    private ConversionService conversionService;
    private ConverterRegistry converterRegistry;

    @Bean
    public ConversionService conversionService() {
        this.conversionService = ConversionServiceFactory.createDefaultConversionService();
        this.converterRegistry = (GenericConversionService) this.conversionService;
        return conversionService;
    }


    @Bean
    @DependsOn(value="conversionService")
    public StringToMapConverter stringToMapConverter() {
        StringToMapConverter stringToMapConverter = new StringToMapConverter();
        stringToMapConverter.setConversionService(this.conversionService);

        ConversionServiceFactory.registerConverters(
                Collections.singleton(stringToMapConverter), this.converterRegistry);

        return stringToMapConverter;
    }
    }

Server startup log

 2012-01-19 20:37:08,108 INFO   [ContextLoader] Root WebApplicationContext: initialization started 
    2012-01-19 20:37:08,142 INFO   [XmlWebApplicationContext] Refreshing Root WebApplicationContext: startup date [Thu Jan 19 20:37:08 IST 2012]; root of context hierarchy 
    2012-01-19 20:37:08,201 INFO   [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/util-context.xml] 
    2012-01-19 20:37:08,342 INFO   [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/service-context.xml] 
    2012-01-19 20:37:08,677 INFO   [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/spring/persistence-context.xml] 
    2012-01-19 20:37:09,215 INFO   [PropertyPlaceholderConfigurer] Loading properties file from class path resource [fn-cars-bundle.properties] 
    2012-01-19 20:37:09,221 INFO   [PropertyPlaceholderConfigurer] Loading properties file from class path resource [fn-cars-bundle.properties] 
    2012-01-19 20:37:09,233 INFO   [DwrAnnotationPostProcessor] Detected candidate bean [asynchronousRequestHandlerServiceImpl]. Remoting using AsyncService 
    2012-01-19 20:37:09,246 INFO   [DwrAnnotationPostProcessor] Could not infer class for [conversionService]. Is it a factory bean? Omitting bean from annotation processing 
    2012-01-19 20:37:09,246 INFO   [DwrAnnotationPostProcessor] Could not infer class for [stringToMapConverter]. Is it a factory bean? Omitting bean from annotation processing 
    2012-01-19 20:37:09,436 INFO   [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@aae8a: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalPersistenceAnnotationProcessor,messageSource,memcachedClient,velocityEngine,smtpAuthenticator,mailSession,mailSender,converterConfig,resourceBundleUtil,dwrAnnotationPostProcessor,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#1,locationDAO,,dataSource,sessionFactory,txManager,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,conversionService,stringToMapConverter,__AsyncService,__dwrConfiguration]; root of factory hierarchy

StringToMapConverter

 public class StringToMapConverter implements ConditionalGenericConverter {

    private static final String COMMA = ",";
    private static final String COLON = ":";

    private ConversionService conversionService;

    /**
     * @param conversionService the conversionService to set
     */
    public void setConversionService(ConversionService conversionService) {
        this.conversionService = conversionService;
    }

    @Override
    public Set<ConvertiblePair> getConvertibleTypes() {
        return Collections.singleton(new ConvertiblePair(String.class, Map.class));
    }

    @Override
    public boolean matches(TypeDescriptor sourceType, TypeDescriptor targetType) {
        boolean matches = 
                this.conversionService.canConvert(sourceType, targetType.getMapKeyTypeDescriptor())
                 && this.conversionService.canConvert(sourceType, targetType.getMapValueTypeDescriptor());
        return matches;
    }

    @SuppressWarnings("unchecked")
    @Override
    public Object convert(Object source, TypeDescriptor sourceType,
            TypeDescriptor targetType) {

        if (source == null) {
            return null;
        }

        String sourceString = (String) source;

        if (sourceString.trim().isEmpty()) {
            return Collections.emptyMap();
        }

        @SuppressWarnings("rawtypes")
        Map targetMap = new HashMap();


        String[] keyValuePairs = sourceString.split(COMMA);
        String[] keyValueArr = null;
        String key = null;
        String value = null;
        for (String keyValuePair : keyValuePairs) {
            keyValueArr = keyValuePair.split(COLON);
            key = keyValueArr[0].trim();
            value = keyValueArr[1].trim();

            Object targetKey = 
                    this.conversionService.convert(
                            key, sourceType, targetType.getMapKeyTypeDescriptor(key));

            targetMap.put(targetKey, value);
        }       

        return targetMap;
    }

}

Can anybody please explain me the reason behind such behavior because the stringToMapConverter bean is created as can be seen in server startup log shown above and how to get this resolved?

Thanks,
Jignesh

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:15:56+00:00Added an answer on May 28, 2026 at 7:15 am

    I have got the issue I posted above resolved and posting my solution here for reference.

    Before posting what was causing the error, I would like to show my <servlet-name>-servlet.xml context file loaded by my application’s Dispatcher Servlet.

    <servlet-name>-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           xmlns:tx="http://www.springframework.org/schema/tx"
    
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
            <context:annotation-config />
    
            <context:component-scan base-package="<MY-PACKAGES>" />
    
            <!-- Handles GET requests for /resources/** by efficiently serving static content in the ${webappRoot}/resources dir -->
            <mvc:resources location="/resources/" mapping="/resources/**"/>
    
            <!--
                This tag registers the HandlerMapping and HandlerAdapter required to dispatch requests to your @Controllers. 
                In addition, it applies sensible defaults based on what is present in your classpath. Such defaults include:
    
                1) Using the Spring 3 Type ConversionService as a simpler and more robust alternative to JavaBeans PropertyEditors
                2) Support for formatting Number fields with @NumberFormat
                3) Support for formatting Date, Calendar, and Joda Time fields with @DateTimeFormat, if Joda Time is on the classpath 
                4) Support for validating @Controller inputs with @Valid, if a JSR-303 Provider is on the classpath 
                5) Support for reading and writing XML, if JAXB is on the classpath 
                6) Support for reading and writing JSON, if Jackson is on the classpath   
             -->
    
            <mvc:annotation-driven/>
    
            <mvc:interceptors>
              <bean class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
                  <property name="sessionFactory">
                      <ref bean="sessionFactory"/>
                  </property>
                  <property name="singleSession" value="false" />
              </bean>
            </mvc:interceptors>
    
            <!-- 
                 Without the following adapter, we'll get a "Does your handler implement a supported interface like Controller?"
                 This is because mvc:annotation-driven element doesn't declare a SimpleControllerHandlerAdapter
                 For more info
                 See http://stackoverflow.com/questions/3896013/no-adapter-for-handler-exception
                 See http://forum.springsource.org/showthread.php?t=48372&highlight=UrlFilenameViewController    
            -->
            <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
    
            <!-- 
                  org.springframework.web.servlet.view.ResourceBundleViewResolver
                  The bundle is typically defined in a properties file, 
                  located in the class path. The default bundle basename is "views". 
            -->
            <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
                 <property name="basename" value="views" />
            </bean>
    
    </beans>
    

    As can be seen in above file I have used <mvc:annotation-driven/> which by default activates the org.springframework.format.support.FormattingConversionService. I needed an instance of org.springframework.core.convert.support.GenericConversionService
    instead, to which I am registering my custom converter StringToMapConverter (shown in my first post) using ConverterConfig (shown in my first post).

    The value of property, at spring container initialization time, org.springframework.web.bind.support.ConfigurableWebBindingInitializer.setConversionService(ConversionService) was getting set as the instance of org.springframework.format.support.FormattingConversionService instead of org.springframework.core.convert.support.GenericConversionService to which i registered my custom converter and thus the error was thrown that no matching editors or conversion strategy found.

    However I don’t need the formatting conversion service in my application as of now and just wanted to register my custom converter.Thus to achieve my goal I used the updated code shown below:

    Updated <servlet-name>-servlet.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xmlns:context="http://www.springframework.org/schema/context"
           xmlns:mvc="http://www.springframework.org/schema/mvc"
           xmlns:tx="http://www.springframework.org/schema/tx"
    
           xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">
    
            <context:annotation-config />
    
            <context:component-scan base-package="<MY-PACKAGES>" />
    
            <!-- Handles GET requests for /resources/** by efficiently serving static content in the ${webappRoot}/resources dir -->
            <mvc:resources location="/resources/" mapping="/resources/**"/>
    
            <!--
                This tag registers the HandlerMapping and HandlerAdapter required to dispatch requests to your @Controllers. 
                In addition, it applies sensible defaults based on what is present in your classpath. Such defaults include:
    
                1) Using the Spring 3 Type ConversionService as a simpler and more robust alternative to JavaBeans PropertyEditors
                2) Support for formatting Number fields with @NumberFormat
                3) Support for formatting Date, Calendar, and Joda Time fields with @DateTimeFormat, if Joda Time is on the classpath 
                4) Support for validating @Controller inputs with @Valid, if a JSR-303 Provider is on the classpath 
                5) Support for reading and writing XML, if JAXB is on the classpath 
                6) Support for reading and writing JSON, if Jackson is on the classpath   
             -->
    
             <!-- 
                  We just require the converter feature not the formatting feature.Thus
                  registering only the org.springframework.core.convert.support.GenericConversionService and 
                  not org.springframework.format.support.FormattingConversionService which
                  <mvc:annotation-driven> activates by default.Also we are registering
                  a custom converter using the com.flightnetwork.cars.controller.util.ConverterConfig
                  class 
             -->
            <!-- Added this to resolve my issue -->
            <mvc:annotation-driven conversion-service="conversionService"/> 
    
            <mvc:interceptors>
              <bean class="org.springframework.orm.hibernate3.support.OpenSessionInViewInterceptor">
                  <property name="sessionFactory">
                      <ref bean="sessionFactory"/>
                  </property>
                  <property name="singleSession" value="false" />
              </bean>
            </mvc:interceptors>
    
            <!-- 
                 Without the following adapter, we'll get a "Does your handler implement a supported interface like Controller?"
                 This is because mvc:annotation-driven element doesn't declare a SimpleControllerHandlerAdapter
                 For more info
                 See http://stackoverflow.com/questions/3896013/no-adapter-for-handler-exception
                 See http://forum.springsource.org/showthread.php?t=48372&highlight=UrlFilenameViewController    
            -->
            <bean class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />
    
            <!-- 
                  org.springframework.web.servlet.view.ResourceBundleViewResolver
                  The bundle is typically defined in a properties file, 
                  located in the class path. The default bundle basename is "views". 
            -->
            <bean id="viewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver">
                 <property name="basename" value="views" />
            </bean>
    
            <!-- Added this to resolve my issue -->
            <bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"/>
    </beans>
    

    Updated ConverterConfig.java

        import java.util.Collections;
    
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.context.annotation.Bean;
        import org.springframework.context.annotation.Configuration;
        import org.springframework.context.annotation.DependsOn;
        import org.springframework.core.convert.ConversionService;
        import org.springframework.core.convert.converter.ConverterRegistry;
        import org.springframework.core.convert.support.ConversionServiceFactory;
    
        @Configuration
        public class ConverterConfig {
    
            @Autowired
            private ConversionService conversionService;
    
            @Autowired
            private ConverterRegistry converterRegistry;
    
            @Bean
            @DependsOn(value="conversionService")
            public StringToMapConverter stringToMapConverter() {
                StringToMapConverter stringToMapConverter = new StringToMapConverter();
                stringToMapConverter.setConversionService(this.conversionService);
    
                ConversionServiceFactory.registerConverters(
                        Collections.singleton(stringToMapConverter), this.converterRegistry);
    
                return stringToMapConverter;
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a foreign key (in SQL Server) by: alter table company add
Have created an attribute property in TableView1.h and pushing that attributes value to another
I have created a user defined type to contain some data that I will
I have created a Silverlight project which also contains a Web project. I have
I have created a custom panel (MyCustomControl) that can contain other controls and be
I have created a map application to show near by places on the map.When
have created a map that I'm trying to have function similar to 'My Maps'.
Have created a c++ implementation of the Hough transform for detecting lines in images.
I have created a template for Visual Studio 2008 and it currently shows up
I have created a custom dialog for Visual Studio Setup Project using the steps

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.