springBoot+mysql+mybatis demo [基本配置] [遇到的问题]
springBoot+mysql+mybatis的基本配置:
多环境

application.properties
spring.profiles.active=dev spring.application.name=resource-make
server.port=8095
server.context-path=/resource-make
指定了工程环境为开发环境、指定应用名字、端口号、上下文路径。
application-dev.properties
#XX文件服务器配置
upload.host = test.ruoob.com.cn
upload.appKey = upload-file-test
upload.appSecret = 8923hjf9f99f9 #XYXY平台服务器上面部署ng地址
xyxy.file.server=http://172.31.12.137:81
常规配置。
application-dev.yml
# DataSource Config
spring:
datasource:
type: org.apache.commons.dbcp2.BasicDataSource
driver-class-name: com.mysql.jdbc.Driver
#com.mysql.cj.jdbc.Driver
#schema: classpath:db/schema-h2.sql
#data: classpath:db/data-h2.sql
url: jdbc:mysql://127.0.0.1:8080/test_10?useUnicode=true&characterEncoding=UTF-8&useSSL=false&useUnicode=true&serverTimezone=Asia/Shanghai
username: root
password: 123123 mybatis:
mapper-locations: classpath:mapper/*.xml
数据库配置:必须配置在xml,否则会有注解冲突问题。
mapper配置:否则无法引入xml。
=======================================================================================
mybatis报错:
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
mybatis配置时出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

同时需要指定xml的位置的配置:
1、mybatis的mapper配置:
mybatis-plus:
mapper-locations: classpath:mapper/*.xml
2、mybatis-plus的mapper配置:
mybatis:
mapper-locations: classpath:mapper/*.xml
注意不要混淆
经验总结:故意写错mybatis的.xml文件,如果项目仍然能够正常启动,说明xml的配置错误,xml没有纳入启动项!
=======================================================================================
mybatis报错:
Property ‘sqlSessionFactory’ or ‘sqlSessionTemplate’ are required
SpringBoot+MyBatis整合中的坑以及Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required错误详解
主要是这个包屏蔽了'sqlSessionFactory' 、 'sqlSessionTemplate'这两个,所以最好的方法是用yml来配置
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
其他的一些重要的依赖:
<dependencies>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>RELEASE</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-extension</artifactId>
<version>3.0.5</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-dbcp2</artifactId>
</dependency>
</dependencies>
经验总结:springBoot+mybatis框架,尽量把数据库配置放到.yml文件,其它配置可以放到.application文件
=======================================================================================
mybatis报错
autowired找不到对应的bean
报错信息:
Description: Field itemMapper in com.iflytek.qqhy.resourcemake.service.ResourceMakeService required a bean of type 'com.iflytek.qqhy.resourcemake.mapper.ItemMapper' that could not be found. Action: Consider defining a bean of type 'com.iflytek.qqhy.resourcemake.mapper.ItemMapper' in your configuration.
解决方法:
@MapperScan(value = {"com.iflytek.qqhy.resourcemake.mapper","com.iflytek.qqhy.resourcemake.dao","com.iflytek.qqhy.resourcemake.datasource"})

解决方法:XML 文件里只配置了Controller的bean 如果你没有启动项目就因为没有配置service和dao的bean 所以会报错 如果启动了项目 那配置扫描需要修改 要可以扫描到service和dao才可以
=======================================================================================
springBoot+mysql+mybatis demo [基本配置] [遇到的问题]的更多相关文章
- SpringBoot集成MyBatis的Bean配置方式
SpringBoot集成MyBatis的Bean配置方式 SpringBoot是一款轻量级开发的框架,简化了很多原先的xml文件配置方式,接下来就介绍一下如何不适用XML来配置Mybatis spri ...
- SpringBoot整合MyBatis之xml配置
现在业界比较流行的数据操作层框架 MyBatis,下面就讲解下 Springboot 如何整合 MyBatis,这里使用的是xml配置SQL而不是用注解.主要是 SQL 和业务代码应该隔离,方便和 D ...
- SpringBoot + MySQL + MyBatis 整合 Redis 实现缓存操作
本地安装 Redis Redis 安装:https://www.cnblogs.com/oukele/p/11373052.html 项目结构: SpringBootRedis 工程项目结构如下: ...
- springboot+mysql+mybatis+Mybatis-Generator+druid 项目demo
1.使用idea新建项目 2.使用Mybatis-Generator自动生成Dao.Model.Mapping相关文件 3.配置application.yml文件 server: port: 8080 ...
- springboot系列七:springboot 集成 MyBatis、事物配置及使用、druid 数据源、druid 监控使用
一.MyBatis和druid简介 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.M ...
- springboot:mybatis多数据源配置
1.application.properties #CMS数据源(主库) spring.datasource.cms.driver-class-name=com.mysql.jdbc.Driver s ...
- springboot值mybatis 别名等配置
在application配置文件中添加如下: mybatis: #该配置替换在sql-config-map中的typeAliases配置 type-aliases-package: com.ww.ww ...
- SpringBoot入门之基于Druid配置Mybatis多数据源
上一篇了解了Druid进行配置连接池的监控和慢sql处理,这篇了解下使用基于基于Druid配置Mybatis多数据源.SpringBoot默认配置数据库连接信息时只需设置url等属性信息就可以了,Sp ...
- SpringBoot系列-整合Mybatis(XML配置方式)
目录 一.什么是 MyBatis? 二.整合方式 三.实战 四.测试 本文介绍下SpringBoot整合Mybatis(XML配置方式)的过程. 一.什么是 MyBatis? MyBatis 是一款优 ...
随机推荐
- 帝国CMS编辑器粘贴Word图片
图片的复制无非有两种方法,一种是图片直接上传到服务器,另外一种转换成二进制流的base64码 目前限chrome浏览器使用,但是项目要求需要支持所有的浏览器,包括Windows和macOS系统.没有办 ...
- Incorporating ASP.NET MVC and SQL Server Reporting Services, Part 2
In the last issue, I introduced you to the basics of incorporating SQL Server Reporting Services int ...
- div页面布局基本布局知识
页面代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF ...
- 01.cordova 安装及项目创建
1.安装cordova cnpm install -g cordova@6.0.0 这里用6.0.0版本,默认下载最新版本,创建项目时候会报错 2.创建项目 cordova create myap ...
- JAVA数组的toString()方法不能直接输出数组内容?
问题描述:我定义了一个类,类名是Job,当我输出Job.toString()是可以按我重载的toString方法输出的,但是如果输出jobs[]这个数组时,只会输出[Lmodel.Job;@45e22 ...
- day34—JavaScript实现DOM操作
转行学开发,代码100天——2018-04-19 1.通过JavaScript元素属性的操作 三种: window.onload =function(){ var oTxt = document.ge ...
- Unity 带骨骼的人体模型换装
直入主题: 1.实验材料 两个模型,虽然缺胳膊少腿的,但是能用!!! 2.条件 两个模型在制作时是基于同一套骨骼,导出模型部位时连着该部位的骨骼一起导出,这样导入到Unity的模型就带有Skinned ...
- Nginx 转写功能和Apache .htaccess 对应
之前一直使用apache 服务器,现有一项目想转到Nginx 服务器运行.. 发现Apache 的撰写功能和 Nginx的不一样.无法通用.hataccess 文件 查阅网上资料,nginx 配置转写 ...
- 笨方法学Python 错误记录
ex8:忘记输入“空格”ex9:忘记输入“冒号”ex14:%前后要空格,否则errorex21:多个函数嵌套,漏写括号)ex24:%d,漏写d,导致程序错误:"""之间的 ...
- Adam Optimization Algorithm
曾经多次看到别人说起,在选择Optimizer的时候默认就选Adam.这样的建议其实比较尴尬,如果有一点科学精神的人,其实就会想问为什么,并搞懂这一切,这也是我开这个Optimizer系列的原因之一. ...