2

Spring Boot application works normal when we run it locally, However if its deployed in PCF, getting below exception:

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.LinkedHashMap<?, ?>] to type [java.lang.String]
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.springframework.core.convert.support.GenericConversionService.handleConverterNotFound(GenericConversionService.java:324)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.springframework.cloud.netflix.archaius.ConfigurableEnvironmentConfiguration.getProperty(ConfigurableEnvironmentConfiguration.java:61)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at com.fdc.ucom.fdcgatewaymockutil.endpoint.ConfigurationController.getProperties(ConfigurationController.java:35)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at com.fdc.ucom.fdcgatewaymockutil.endpoint.ConfigurationController.lambda$getConfig$1(ConfigurationController.java:58)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at java.util.Iterator.forEachRemaining(Iterator.java:116)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.apache.commons.configuration.AbstractConfiguration.getString(AbstractConfiguration.java:1038)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.apache.commons.configuration.AbstractConfiguration.getString(AbstractConfiguration.java:1021)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at java.lang.reflect.Method.invoke(Method.java:498)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
2018-01-04T09:47:39.232-06:00 [APP/PROC/WEB/0] [OUT] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
Aniruddha Das
  • 20,520
  • 23
  • 96
  • 132
user1568854
  • 37
  • 1
  • 8
  • What is your Spring Boot version? Please share your dependencies. One reason could be that you added the libs manually in an IDE and it starts because of that. What happens if you run gradle bootRun from the terminal? – Turbut Alin Jan 04 '18 at 19:02
  • using spring boot 1.5.4.RELEASE with cloud version of Edgware.RELEASE, mvn boot run doesn't seems to be having any issues locally. – user1568854 Jan 04 '18 at 19:09
  • @user1568854, have you found a solution for the problem ? I have the same issue ... – Alexander.Furer Jan 11 '18 at 09:00
  • @Alexander.Furer, Nope, we skipped this conversion by adding a try/catch. the problem was, cups that were defined in PCF that gets pulled by ConfigurationManager, some of the object type contains LinkedHashMap. – user1568854 Jan 12 '18 at 11:41

1 Answers1

0

You can create a custom converter as follows:

@Component
public class LinkedHashMap2String implements Converter<LinkedHashMap, String> {

    @Override
    public String convert(LinkedHashMap source) {
        return source.toString();
    }
}

And then add this convertor into the GenericConversionList as follows:

@Configuration
public class SpringConvertors {

    @Bean
    public ConversionService conversionService(LinkedHashMap2String linkedHashMap2String) {
        ConversionServiceFactoryBean conversionServiceFactory = new ConversionServiceFactoryBean();
        conversionServiceFactory.setConverters(Sets.newHashSet(linkedHashMap2String);
        conversionServiceFactory.afterPropertiesSet();
        return conversionServiceFactory.getObject();
    }
}
Turbut Alin
  • 2,568
  • 1
  • 21
  • 30
  • 1
    if I do this, I get this error during the start up---date=2018-01-04 Description:A component required a bean named 'defaultConversionService' that could not be found.Action:Consider defining a bean named 'defaultConversionService' in your configuration. – user1568854 Jan 04 '18 at 21:06
  • 1
    The method is `setConverters` not `setConvertors` – ScottSummers Jan 01 '19 at 12:20