SpirngBoot整合MyBatis出现“SAXParseException”和“文件提前结束”异常解决办法
故障現(xiàn)象:
程序是使用 SpringBoot 整合 MyBatis 的,在idea下運行的時候沒有任何問題,但是打包成 jar 包單獨運行就出問題,不論是在 Windows 環(huán)境下還是在 Linux 環(huán)境下,都是一樣,可以排除系統(tǒng)環(huán)境問題。主要的堆棧信息提取出來是如下:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'class path resource [mapper/]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; 文件提前結(jié)束
解決辦法:
Spring Boot 的配置文件 application.properties 文件中的配置項 mybatis.mapper-locations 有問題,原本設(shè)置內(nèi)容是:
| mybatis.mapper-locations=classpath:mapper/** |
將配置修改為,這里為了保險起見,將 MyBatis 的mapper文件夾的目錄也修改了一下
| mybatis.mapper-locations=classpath:mappers/*.xml |
重新打包,打出來的包問題再沒有重現(xiàn)
總結(jié)
以上是生活随笔為你收集整理的SpirngBoot整合MyBatis出现“SAXParseException”和“文件提前结束”异常解决办法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java实现读取服务器上的图片并进行ba
- 下一篇: spring boot+shiro中使用