springmvc配置多视图时的异常

单配置freemaker跳转html视图,启动tomcat后报错,Caused by: java.lang.NoClassDefFoundError: freemarker/cache/TemplateLoader

	<!-- 视图解析器-->
    <bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
        <property name="templateLoaderPath" value="/WEB-INF/views/"/>
    </bean>
   <bean id="freemarkerConfiguration" class="org.springframework.beans.factory.config.PropertiesFactoryBean"></bean>
   
	<!-- html视图解析 -->
    <bean id="htmlViewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.freemarker.FreeMarkerView"/>
        <property name="contentType" value="text/html; charset=utf-8"/>
        <property name="cache" value="true"/>
        <property name="suffix" value=".html"/>
        <property name="order" value="2"/>
    </bean>

控制台异常:

严重:StandardWrapper.Throwablejava.lang.NoClassDefFoundError:freemarker/cache/TemplateLoader
Caused by: java.lang.ClassNotFoundException: freemarker.cache.TemplateLoader
四月 24, 2020 3:48:49 下午 org.apache.catalina.core.StandardContext loadOnStartup
严重: Servlet [dispatcherServlet] in web application [/phone_query] threw load() exception
java.lang.ClassNotFoundException: freemarker.cache.TemplateLoader

错误原因

通过“Caused by: java.lang.NoClassDefFoundError: freemarker/cache/TemplateLoader”,可知缺少freemarker的jar包

解决办法

通过https://freemarker.apache.org/freemarkerdownload.html页面下载freemarker相应的jar包,然后复制到lib文件夹中,注意要下载2.3.15以上的版本,否则项目启动后在访问html时会爆下面的异常

严重: Servlet.service() for servlet [dispatcherServlet] in context with path [/phone_query] threw exception [Handler processing failed; nested exception is java.lang.IllegalAccessError: tried to access class freemarker.ext.servlet.AllHttpScopesHashModel from class org.springframework.web.servlet.view.freemarker.FreeMarkerView] with root cause
java.lang.IllegalAccessError: tried to access class freemarker.ext.servlet.AllHttpScopesHashModel from class org.springframework.web.servlet.view.freemarker.FreeMarkerView
springmvc配置多视图时的异常_第1张图片

你可能感兴趣的:(springmvc多视图配置)