Spring Boot应用程序在我们本地运行时工作正常,但如果它部署在PCF
中,则低于异常:
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)
答案 0 :(得分:0)
您可以按如下方式创建自定义转换器:
@Component
public class LinkedHashMap2String implements Converter<LinkedHashMap, String> {
@Override
public String convert(LinkedHashMap source) {
return source.toString();
}
}
然后将此转换器添加到GenericConversionList
中,如下所示:
@Configuration
public class SpringConvertors {
@Bean
public ConversionService conversionService(LinkedHashMap2String linkedHashMap2String) {
ConversionServiceFactoryBean conversionServiceFactory = new ConversionServiceFactoryBean();
conversionServiceFactory.setConverters(Sets.newHashSet(linkedHashMap2String);
conversionServiceFactory.afterPropertiesSet();
return conversionServiceFactory.getObject();
}
}