描述:在配置视图控制器后,开启服务器后页面报错:
Servlet.init() for servlet springmvc threw exception
<!-- 自动扫描包 -->
<context:component-scan base-package="com.springmvc.controller"/>
<!-- 配置Thymeleaf视图解析器 -->
<bean id="viewResolver"
class="org.thymeleaf.spring5.view.ThymeleafViewResolver">
<property name="order" value="1"/>
<property name="characterEncoding" value="UTF-8"/>
<property name="templateEngine">
<bean class="org.thymeleaf.spring5.SpringTemplateEngine">
<property name="templateResolver">
<bean
class="org.thymeleaf.spring5.templateresolver.SpringResourceTemplateResolver">
<!-- 视图前缀 -->
<property name="prefix" value="/WEB-INF/templates/"/>
<!-- 视图后缀 -->
<property name="suffix" value=".html"/>
<property name="templateMode" value="HTML5"/>
<property name="characterEncoding" value="UTF-8" />
</bean>
</property>
</bean>
</property>
<!--误把视图控制器写入这里,所以servlet初始化方法报错-->
</bean>
</beans>
另外,需注意:
若开启视图控制器,则只有视图控制器的请求会被处理其余全部404,此时必须再配置一个标签: <mvc:annotation-driven/>