.PersistenceException: ### Error querying database.Cause: java.lang.NullPointerException
2020-07-24 16:42
99 查看
错误
[org.apache.ibatis.io.ResolverUtil]-Checking to see if class com.wei.mapper.UserMapper matches criteria [is assignable to Object] [org.apache.ibatis.transaction.jdbc.JdbcTransaction]-Opening JDBC Connection org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: java.lang.NullPointerException ### The error may exist in com/wei/mapper/UserMapper.xml ### The error may involve com.wei.mapper.UserMapper.findAll ### The error occurred while executing a query ### Cause: java.lang.NullPointerException at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141) at org.apache.ibatis.binding.MapperMethod.executeForMany(MapperMethod.java:137) at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:75) at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:59) at com.sun.proxy.$Proxy3.findAll(Unknown Source) at MybatisTest.fun1(MybatisTest.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.junit.runner.JUnitCore.run(JUnitCore.java:160) at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68) at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33) at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230) at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58) Caused by: java.lang.NullPointerException at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:936) at java.util.concurrent.ConcurrentHashMap.containsKey(ConcurrentHashMap.java:964) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.initializeDriver(UnpooledDataSource.java:207) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:200) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:196) at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:93) at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:404) at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:90) at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:139) at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:61) at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336) at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84) at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62) at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324) at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109) at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83) at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148) ... 28 more Process finished with exit code -1
原因
- Error querying database. Cause: java.lang.NullPointerException
The error may exist in com/wei/mapper/UserMapper.xml
The error may involve com.wei.mapper.UserMapper.findAll
The error occurred while executing a query - 虽然它说明错误可能在UserMapper.xml , 但是我昨天运行是没有问题的,然后今天就只修改了主配置文件,这里有误导性。
- 本次错误的原因是因为数据源没有注入,只在properties标签里有数据库的相关信息。
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd"> <configuration> <properties> <property name="driver" value="com.mysql.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/mybatis"/> <property name="username" value="root"/> <property name="password" value="root"/> </properties> <settings> <setting name="mapUnderscoreToCamelCase" value="true"/> <setting name="logImpl" value="LOG4J"/> </settings> <environments default="mysql"> <environment id="mysql"> <transactionManager type="JDBC"></transactionManager> <dataSource type="POOLED"> <!--<property name="driver" value="${driver}"/> <property name="url" value="${url}"/> <property name="username" value="${username}"/> <property name="password" value="${password}"/>--> </dataSource> </environment> </environments> <mappers> <package name="com.wei.mapper" /> </mappers> </configuration>
解决
- 只需将数据源dataSource 里引入数据库信息即可。
<dataSource type="POOLED"> <property name="driver" value="${driver}"/> <property name="url" value="${url}"/> <property name="username" value="${username}"/> <property name="password" value="${password}"/> </dataSource>
相关文章推荐
- Android 发送短信 抛出Caused by: java.lang.NullPointerException 09-18 15:11:00.905: E/AndroidRuntime(10159)
- An internal error occurred during: "Launching atphone".java.lang.NullPointerException
- ?--Porg.springframework.beans.MethodInvocationException: Property 'username' threw exception; nested exception is java.lang.NullPointerException
- org.apache.jasper.JasperException: java.lang.NullPointerException 解决办法
- Java异常解决之--java.lang.NullPointerException
- 解决kylin build cube第一步报错:java.lang.NullPointerException
- ViewPager&Fragment组合由于单例模式导致java.lang.NullPointerException异常
- 异常: Exception starting filter struts2 java.lang.NullPointerException
- win7 spark运行本地程序文件出错 error:avaSparkContext. : java.lang.NullPointerException
- smartupload组件上传出现java.lang.NullPointerException: charsetName
- java.lang.NullPointerException:
- java.lang.NullPointerException
- FlashBuilder 新建项目时提示 java.lang.nullpointerexception
- 实际编写中的注解问题,@Autowired位置写错,报错java.lang.NullPointerException
- java.lang.NullPointerException org.apache.jsp.index_jsp._jspInit(index_jsp.java:22)
- 关于android广播包监听网络状态变化收到java.lang.NullPointerException: Error receiving broadcast Intent
- [异常] MyEclipse Deploy点不开 An internal error occurred during: "Launching MVC on Tomcat 6.x". java.lang.NullPointerException
- Exception in thread "main" java.lang.NullPointerException的问题
- Errors running builder 'Android Resource Manager' on Project java.lang.NullPointerException
- Java newInstance(); 报 java.lang.NullPointerException 异常