Springboot 问题记录

Springboot 问题记录

父级起步依赖版本1.5.9.RELEASE
一、springboot整合mybatis报错。
错误一
**原因:application.properties中混淆了mybatis.config-location=classpath:com/taotao/springbootmybatis/mapper/*.xml
和mybatis.config-locations=classpath:com/taotao/springbootmybatis/mapper/*.xml
前者参数为String,且不支持通配符
。后者参数为String[],支持

日志如下:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘mybatisTestController’: Unsatisfied dependency expressed through field ‘service’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘mybatisTestServiceImpl’: Unsatisfied dependency expressed through field ‘tbItemMapper’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘tbItemMapper’ defined in file [I:\TaoTao\gitee\code01\springboot-mybatis\target\classes\com\taotao\springbootmybatis\mapper\TbItemMapper.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 [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: 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 java.io.FileNotFoundException: class path resource [com/taotao/springbootmybatis/mapper/*.xml] cannot be opened because it does not exist

错误二:
原因:其实也是混淆了mybatis.config-location以及mybatis.config-locations两个配置项。
错误的配置了mybatis.config-location=classpath:com/taotao/springbootmybatis/mapper/TbItemMapper.xml
正确配置为mybatis.config-locations=classpath:com/taotao/springbootmybatis/mapper/*.xml
日志:
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘mybatisTestController’: Unsatisfied dependency expressed through field ‘service’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘mybatisTestServiceImpl’: Unsatisfied dependency expressed through field ‘tbItemMapper’; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘tbItemMapper’ defined in file [I:\TaoTao\gitee\code01\springboot-mybatis\target\classes\com\taotao\springbootmybatis\mapper\TbItemMapper.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 [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: 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 config resource: class path resource [com/taotao/springbootmybatis/mapper/TbItemMapper.xml]; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.lang.NullPointerException

二、springboot中的406(Not Acceptable)错误
可能的原因:
1.未引入jackson的相关jar包

<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-databind</artifactId>
	</dependency>
	这个一般在SSM框架中很可能出现,但是在springboot中,只要依赖了spring-boot-starter-web,就会引入,所以基本不会出现

2.某些pojo类,没有给默认的构造方法。
由于springboot中使用了大量发射机制,反射必须依赖默认的无参构造器。
所以pojo必须给出默认的无参构造器。

三、mybatis的Invalid bound statement (not found)
根据以下可能原因排查:
1.mapper.xml 属性对应的mapper.java 是否 拼写错误,包路径是否正确
2.mapper.xml的id即方法名称,和mapper.java 是否一致
3.mapper.xml定义的方法返回值,和mapper.java 是否一致
4.mapper.xml的SQL语句是否有问题
5.mapper.xml有没有被系统加载起来?

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值