配置mvc:default-servlet-handler 出现Configuration problem: Cannot locate BeanDefinitionDecorator fo

原配置文件

<?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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">

        <!--开启handlemapper handleadapter-->
        <mvc:annotation-driven/>
        <!--controller配置-->
        <context:component-scan base-package="it.heima.controller"/>
        <!--配置视图解析器-->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <!--前缀-->
            <property name="prefix" value="/WEB-INF/views/"/>
            <!--后缀-->
            <property name="suffix" value=".jsp"/>

            <!--配置放行静态资源,交给web服务器处理,所以页面展示就出现效果-->
            <mvc:default-servlet-handler/>
        </bean>
</beans>

报错信息:

原因:通过反复尝试发现配置信息<mvc:default-servlet-handler/>位置放错,应该放bean外面.

正确如下:

<?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:mvc="http://www.springframework.org/schema/mvc"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
       http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/mvc
       http://www.springframework.org/schema/mvc/spring-mvc.xsd
       http://www.springframework.org/schema/context
       http://www.springframework.org/schema/context/spring-context.xsd">

        <!--开启handlemapper handleadapter-->
        <mvc:annotation-driven/>
        <!--controller配置-->
        <context:component-scan base-package="it.heima.controller"/>
        <!--配置视图解析器-->
        <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <!--前缀-->
            <property name="prefix" value="/WEB-INF/views/"/>
            <!--后缀-->
            <property name="suffix" value=".jsp"/>
            
        </bean>

        <!--配置放行静态资源,交给web服务器处理,所以页面展示就出现效果-->
         <mvc:default-servlet-handler/>
</beans>

猜你喜欢

转载自blog.csdn.net/weixin_42333583/article/details/81773945