org.springframework.core.convert.ConversionFailedException mvc:resources与conversionService报错问题 - Go语言中文社区

org.springframework.core.convert.ConversionFailedException mvc:resources与conversionService报错问题


原文:https://www.cnblogs.com/Gyoung/articles/5457846.html

 

最近在代码中加了mvc资源的注册

    <mvc:resources mapping="/assets/**" location="assets/"/>

而后因为时间问题,又加了spring转换器的bean

复制代码

 <bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">
        <property name="messageConverters">
            <list>
                <ref bean="mappingFastJsonHttpMessageConverter"/> <!-- JSON转换器 -->
            </list>
        </property>
        <property name="webBindingInitializer">
            <bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
                <property name="conversionService" ref="conversionService" />
            </bean>
        </property>
    </bean>

    <!--格式转换-->
    <bean id="conversionService" class="org.springframework.format.support.DefaultFormattingConversionService"/>

复制代码

当日志格式为DEBUG的时候,看到了有报错

复制代码

org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.util.ArrayList<?>] to type [java.util.List<org.springframework.core.io.Resource>] for value '[assets/]'; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.util.ArrayList<?>] to type [org.springframework.core.io.Resource]
    at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41)
    at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:192)
    at org.springframework.beans.TypeConverterDelegate.convertIfNecessary(TypeConverterDelegate.java:173)
    at org.springframework.beans.AbstractNestablePropertyAccessor.convertIfNecessary(AbstractNestablePropertyAccessor.java:576)
    at org.springframework.beans.AbstractNestablePropertyAccessor.convertForProperty(AbstractNestablePropertyAccessor.java:603)
    at org.springframework.beans.BeanWrapperImpl.convertForProperty(BeanWrapperImpl.java:204)

复制代码

多次dubug后发现,如果有注册mvc:resources,同时配置文件中又有id为"conversionService"的bean,就会报错

解决方法就是将conversionService的bean id修改了。很奇怪的问题。

 

修改成这样就ok了.

项目配置太老了,该换了大笑

 

                                                                               微信公众号: 

                                               

                                                                             JAVA程序猿成长之路

                          分享资源,记录程序猿成长点滴。专注于Java,Spring,SpringBoot,SpringCloud,分布式,微服务。 

版权声明:本文来源CSDN,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/niugang0920/article/details/80411332
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2020-02-25 01:07:44
  • 阅读 ( 1139 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢