springboot配置热部署后mybatis报错this web application instance has been stopped already could not load mybatis mapper

  • A+
所属分类:SpringBoot

---
title: "SpringBoot配置热部署后mybatis报错this web application instance has been stopped already. Could not load [mybatis/mapper/]"
date: 2019-07-24 08:01:22
categories: SpringBoot
tags:
- 报错
- SpringBoot
- mybatis
- 热部署
---

目前这个项目快完了,才想起来弄下热部署,也是为以后项目方便吧,按照网上的教程

  • 1.在pom文件里增加依赖
<!-- 热部署 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <optional>true</optional> <!-- 这个需要为 true 热部署才有效 -->
            <scope>runtime</scope>
        </dependency>
  • 2.在intellij idea的file->settings->compiler里勾选Build Project automatically

springboot配置热部署后mybatis报错this web application instance has been stopped already could not load mybatis mapper

  • 3.按下快捷键alt+ctrl+shift+/,在以下画面点击Registry

springboot配置热部署后mybatis报错this web application instance has been stopped already could not load mybatis mapper

  • 4.勾选Compiler autoMake allow when app running

 

springboot配置热部署后mybatis报错this web application instance has been stopped already could not load mybatis mapper

但问题是按上面4步配完后随便修改一个类的代码时,控制台自动重启时会报错

this web application instance has been stopped already. Could not load [mybatis/mapper/]

很明显问题是重启时没有找到mybatis的xml文件的路径。

百度了很多,有的说不能用spring-boot-devtools,得用springloaded,这个试了,是不报错了,但是根本不会自动重启,pass。。。

还有的说要在pom文件里的<build>里加上mybatis的配置文件的路径的配置,感觉有点靠谱的,但还是没用。。。

最后说在application.yml里加上mapper-locations指定mybatis的classpath。。这个最让我无语,因为我本身项目里就加了这个啊。。起始以为这个也不行,但是后来仔细看了下具体的路径配置,发现有一点区别。

我的配置是

mapper-locations: classpath:mybatis/mapper/*.xml

但网上有的例子里这个classpath后面有一个*号。。我抱着试一试的心态加上了这个*后就好了!!!!

正确写法如下:

mapper-locations: classpath*:mybatis/mapper/*.xml

网上暂时还没有我这种情况的,希望有同样情况的能解决你们的问题!

ZPY

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: