mybatis学习笔记十——异常问题

一、

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误

原因:idea自动过滤掉了src/main/java下的配置文件,因为一般配置文件都是放在src/main/resource下的。

解决方法:将*Mapper.xml复制进去

 

二、

java.lang.NullPointerException
    at Test.Test(Test.java:25)

原因:spring中JUnit4单元测试时需要在测试类中添加注解

解决方法:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring/spring-main.xml")

三、

//
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userserviceImpl': Unsatisfied dependency expressed through field 'userMapping'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userMapping' defined in file [E:\项目_java工作\whadmin\target\classes\cn\ect\sys\mapper\UserMapping.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring/spring-main.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are:

 

原因:pom中没有添加spring-jdbc的jar包

解决方法:

<dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>

 

四、

[INFO][2019-08-06 12:43:51,825][com.alibaba.druid.pool.DruidDataSource]{dataSource-1} inited
[ERROR][2019-08-06 12:43:52,245][com.alibaba.druid.pool.DruidDataSource]create connection SQLException, url: jdbc:mysql://127.0.0.1:3306/whadmin?useUnicode=true&characterEncoding=utf8&characterSetResults=utf8, errorCode 1045, state 28000
java.sql.SQLException: Access denied for user 'Timor'@'localhost' (using password: YES)

原因:数据库链接异常(spring配置异常、或者db.properties异常)

<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />

解决方法:改改改spring配置或者db.properties文件

 

五、

六、

七、

八、

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值