求解?求解?SpringMVC的Servlet[springMVC]的Servlet.init()引发异常

路径网上都说依赖和版本的问题,我这都是使用的最新版不知道问题出在哪啊,求告解
​​

img

依赖

<!-- SpringMVC -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>6.0.6</version>
        </dependency>

        <!-- 日志 -->
        <dependency>
            <groupId>ch.qos.logback</groupId>
            <artifactId>logback-classic</artifactId>
            <version>1.4.6</version>
        </dependency>

        <!-- ServletAPI -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>4.0.1</version>
            <scope>provided</scope>
        </dependency>

        <!-- Spring5和Thymeleaf整合包 -->
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring5</artifactId>
            <version>3.1.1.RELEASE</version>
        </dependency>

img

 springMVC.xml文件内容

<!-- 自动扫描包 -->
    <context:component-scan base-package="com.atguigu.mvc.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>
    </bean>


相关类

​
@Controller
public class HelloController {

    //"/"-->WEB-INF/templates/index.xml

    // @RequestMapping注解:处理请求和控制器方法之间的映射关系
    // @RequestMapping注解的value属性可以通过请求地址匹配请求,/表示的当前工程的上下文路径
    // localhost:8080/springMVC/
    @RequestMapping("/")
    public String index() {
        //返回视图名称
        return "index";
    }
}

index.HTML

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
</head>
<body>
<h1>首页</h1>
</body>
</html>

报错


​
org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'viewResolver' defined in class path resource[springMVC.xml]: 

Cannot create inner bean 'org.thymeleaf.spring5.SpringTemplateEngine#5b2fff4b' 
of type [org.thymeleaf.spring5.SpringTemplateEngine] while setting bean property 'templateEngine'

​

需要远程看下

  • 这篇文章:【SSM】SpringMVC运行报错:500 Servlet[SpringMVC]的Servlet.init()引发异常 描述 服务器遇到一个意外的情况,阻止它完成请求。 也许有你想要的答案,你可以看看
  • 除此之外, 这篇博客: Servlet[springmvc]的Servlet.init()引发异常;中的 寻找错误原因:  部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • 通过报错信息可以看到,是Spring MVC的DispatcherServlet无法初始化;

    ……………………………………………………

    而,可以发现我们初始化DispatcherServlet的时候,是需要加载applicationContext.xml(初始化IoC容器)的;

    那么,很自然就能想到,之所以DispatcherServlet无法初始化,是不是因为在初始化IoC容器的时候出现问题了呐?自然,就会想到,是不是applicationContext.xml中【是否存在无法初始化的bean】或者【applicationContext.xml文件哪儿配置错了嘞】;

    ……………………………………………………

    再瞅一眼报错信息:通过报错信息,也发现是【有一个name=conversionService的bean,是没有的】;

    ……………………………………………………

    查看applicationContext.xml中的内容,果然发现了一个无法被初始化的bean“conversionService”;


     即,错误原因是:因为抄了旧代码,而旧代码没有处理干净:没有抄“conversionService”的bean实体,但是却抄了“conversionService”。所以,IoC容器初始化失败,从而导致DispatcherServlet也不能正常初始化了。