mybatis報錯
20200928資源匯出失敗的問題
20200928資源匯出失敗的問題
方案一:
控制檯報錯資訊:
java.lang.ExceptionInInitializerError
at com.ajie.mapper.UserDaoTest.test(UserDaoTest.java:18)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in com/ajie/mapper/UserMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/ajie/mapper/UserMapper.xml
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
at com.ajie.utils.MyBatiUtils.<clinit>(MyBatiUtils.java:25)
... 26 more
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/ajie/mapper/UserMapper.xml
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:98)
at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78)
... 28 more
Caused by: java.io.IOException: Could not find resource com/ajie/mapper/UserMapper.xml
at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:114)
at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:100)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:372)
at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:119)
... 30 more
Process finished with exit code -1
解決方法:
在pox.xml
中新增:
<!--在build中配置resources,來防止我們資源匯出失敗的問題-->
<build>
<resources>
<!--可以不加這個 resource ,idea預設匯出這個-->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<!--必須加這個 resource -->
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
問題分析:
報錯的原因是 java
包下存在xml
檔案不能匯出:如果把資原始檔放在java
目錄下,idea資源匯出會出現失敗,不會在對應的class檔案中生成對應的資原始檔。
錯誤資訊 The error may exist in com/ajie/mapper/UserMapper.xml
,Cause: java.io.IOException: Could not find resource com/ajie/mapper/UserMapper.xml
解決分析:
設定Maven靜態資源過濾
<resource>
<!--匯出src/main/resources 裡的資源 -->
<directory>src/main/resources</directory>
<includes>
<!--包含 *.properties和*.xml檔案-->
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<resource>
<!--匯出src/main/java 裡的資源 -->
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
方案二:
解決思路:
將mapper.xml
檔案放在resources
目錄下,idea會正常資源匯出,並在對應的class檔案中生成對應的資原始檔。
解決方法:3
1.我的mapper.xml
存放目錄mybatis/mapper/UserMapper.xml
.
2.修改mybatis-config.xml
檔案
<!--每一個Mapper.XML都需要在Mybatis核心配置檔案中註冊!-->
<mappers>
<mapper resource="mybatis/mapper/UserMapper.xml"/>
</mappers>
作者隨著學習,持續更新…
相關文章
- mybatis報錯解決MyBatis
- mybatis plus saveBatch報錯問題MyBatis
- mybatis 報錯: Invalid bound statement (not found)MyBatis
- mybatis3呼叫瀚高procedure報錯MyBatisS3
- Mybatis批量更新SQL報錯☞解決辦法MyBatisSQL
- Spring整合Mybatis時Mapper代理報錯BindingExceptionSpringMyBatisAPPException
- 使用mybatis報錯:Error setting non null for parameter #4 with JdbcType TIMESTAMPMyBatisErrorNullJDBC
- mybatis引數型別錯誤MyBatis型別
- JavaScript報錯型別(報錯速查)JavaScript型別
- mybatis竟然報"Invalid value for getInt()"MyBatis
- MyBatis 錯誤:Invalid bound statement (not found)MyBatis
- 關於mybatis tomcat 和jetty啟動報 {dataSource-1} inited 錯誤的記錄MyBatisTomcatJetty
- eclipse使用mybatis generator自動生成程式碼報錯Generation Warnings Occured Project E: doesEclipseMyBatisProject
- mybatis plus 執行sql報錯 CommunicationsException, druid version 1.2.13, jdbcUrl : jdbc:mysql://XXXMyBatisExceptionUIJDBCMySql
- JavaScript報錯JavaScript
- spark報錯Spark
- redis報錯Redis
- 報錯集
- 報錯+2
- playsound報錯
- 前端報錯前端
- dhcp報錯
- springcloud報錯報UnsatisfiedDependencyExceptionSpringGCCloudException
- asm報錯一例-support 報錯rename failedASMAI
- java.lang.AbstractMethodError: org.mybatis.spring.transaction.SpringManagedTransaction.getTimeout()Ljava/lang/Integer; 報錯解決JavaErrorMyBatisSpring
- SpingBoot - Mybatis報錯:For artifact {com.mysql:mysql-connector-j:null:jar}: The version cannot be empty.bootMyBatisMySqlNullJAR
- Eclipse中使用Mybatis Generator遇到的錯誤EclipseMyBatis
- flutter路由報錯Flutter路由
- pycharm import 報錯PyCharmImport
- 埠占用報錯
- webpack build報錯WebUI
- oracle dg報錯Oracle
- python報錯Python
- import moviepy 報錯Import
- 歸檔報錯
- oracle emctl 報錯Oracle
- asmlib 報錯ASM
- jsp報錯JS