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
- mybatis3呼叫瀚高procedure報錯MyBatisS3
- Mybatis批量更新SQL報錯☞解決辦法MyBatisSQL
- 使用mybatis報錯:Error setting non null for parameter #4 with JdbcType TIMESTAMPMyBatisErrorNullJDBC
- mybatis plus 執行sql報錯 CommunicationsException, druid version 1.2.13, jdbcUrl : jdbc:mysql://XXXMyBatisExceptionUIJDBCMySql
- mybatis引數型別錯誤MyBatis型別
- 13.MyBatis報錯:Error querying database. Cause: org.apache.ibatis.binding.BindingException: ParameterMyBatisErrorDatabaseApacheException
- mybatis竟然報"Invalid value for getInt()"MyBatis
- 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
- JavaScript報錯型別(報錯速查)JavaScript型別
- Eclipse中使用Mybatis Generator遇到的錯誤EclipseMyBatis
- springcloud報錯報UnsatisfiedDependencyExceptionSpringGCCloudException
- mybatis(錯誤) 專案啟動時報“Result Maps collection already contains value forxxx”的解決方案MyBatisAI
- redis報錯Redis
- hive 報錯Hive
- spark報錯Spark
- dhcp報錯
- 報錯+2
- 前端報錯前端
- playsound報錯
- 報錯集合
- modprobe報錯
- JavaScript報錯JavaScript
- 報錯集
- pnpm 報錯NPM
- Jenkins報錯Jenkins
- vscode使用chrome除錯報錯VSCodeChrome除錯
- npm install 報錯NPM
- NBU報錯83
- pandas merge報錯
- Django 報錯 TemplateDoesNotExistDjango
- 又又報錯
- 20200126 - PHP 報錯PHP
- flutter路由報錯Flutter路由
- mysqlbinlog工具報錯MySql
- python的報錯Python