0

创建视图解析器时出现以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'viewResolver' defined in ServletContext resource [/WEB-INF/webmvc-config.xml]: 
Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: 
Failed to convert property value of type 'java.lang.String' to required type 'java.lang.String' for property 'prefix'; 
nested exception is java.lang.IllegalArgumentException: No class 'java.lang.String' was registered

我的 spring webmvc 配置如下所示:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

    <context:component-scan base-package="com.mycompany.web" use-default-filters="false">
        <context:include-filter expression="org.springframework.stereotype.Controller" type="annotation" />
    </context:component-scan>

    <mvc:annotation-driven conversion-service="conversionService" />

    <bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"/>

    <bean class="org.springframework.data.repository.support.DomainClassConverter">
        <constructor-arg ref="conversionService"/>
    </bean>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:prefix="/WEB-INF/views/" p:suffix=".jsp" />

</beans>

它与conversionService有关吗?

4

1 回答 1

1

如果您不需要注册自定义转换器或格式化程序,您可以尝试从 mvc:annotation-driven 元素中删除conversionService bean 声明以及conversion-service 属性。

只需<mvc:annotation-driven/>启用默认格式规则就足够了:

http://docs.spring.io/spring/docs/3.2.4.RELEASE/spring-framework-reference/html/validation.html#format-configuring-formatting-mvc

于 2013-10-23T02:36:50.370 回答