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 [基本配置] [遇到的问题]的更多相关文章

  1. SpringBoot集成MyBatis的Bean配置方式

    SpringBoot集成MyBatis的Bean配置方式 SpringBoot是一款轻量级开发的框架,简化了很多原先的xml文件配置方式,接下来就介绍一下如何不适用XML来配置Mybatis spri ...

  2. SpringBoot整合MyBatis之xml配置

    现在业界比较流行的数据操作层框架 MyBatis,下面就讲解下 Springboot 如何整合 MyBatis,这里使用的是xml配置SQL而不是用注解.主要是 SQL 和业务代码应该隔离,方便和 D ...

  3. SpringBoot + MySQL + MyBatis 整合 Redis 实现缓存操作

    本地安装 Redis Redis 安装:https://www.cnblogs.com/oukele/p/11373052.html 项目结构:  SpringBootRedis 工程项目结构如下: ...

  4. springboot+mysql+mybatis+Mybatis-Generator+druid 项目demo

    1.使用idea新建项目 2.使用Mybatis-Generator自动生成Dao.Model.Mapping相关文件 3.配置application.yml文件 server: port: 8080 ...

  5. springboot系列七:springboot 集成 MyBatis、事物配置及使用、druid 数据源、druid 监控使用

    一.MyBatis和druid简介 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.M ...

  6. springboot:mybatis多数据源配置

    1.application.properties #CMS数据源(主库) spring.datasource.cms.driver-class-name=com.mysql.jdbc.Driver s ...

  7. springboot值mybatis 别名等配置

    在application配置文件中添加如下: mybatis: #该配置替换在sql-config-map中的typeAliases配置 type-aliases-package: com.ww.ww ...

  8. SpringBoot入门之基于Druid配置Mybatis多数据源

    上一篇了解了Druid进行配置连接池的监控和慢sql处理,这篇了解下使用基于基于Druid配置Mybatis多数据源.SpringBoot默认配置数据库连接信息时只需设置url等属性信息就可以了,Sp ...

  9. SpringBoot系列-整合Mybatis(XML配置方式)

    目录 一.什么是 MyBatis? 二.整合方式 三.实战 四.测试 本文介绍下SpringBoot整合Mybatis(XML配置方式)的过程. 一.什么是 MyBatis? MyBatis 是一款优 ...

随机推荐

  1. Java泛型与集合笔记

    第一章 Java的泛型为了兼容性和防止代码爆炸,在编译成字节碼时会进行类型擦除,编译器自动添加代码做类型转换(用到List<Integer>的地方用Integer来做转换),自动做装箱拆箱 ...

  2. drf 的分页功能

    1 settings中配置 page_size = 20 代表每页20条数据 REST_FRAMEWORK = { 'DEFAULT_PARSER_CLASSES': ( 'rest_framewor ...

  3. jquery常用用法

    1.$("prve + next" )                          选择紧接着在perve后的next元素2.$("#div1 > *&quo ...

  4. [NOIP2016][luogu]换教室[DP]

    [NOIP2016] Day1 T3 换教室 ——!x^n+y^n=z^n 题目描述 对于刚上大学的牛牛来说,他面临的第一个问题是如何根据实际情况申请合适的课程. 在可以选择的课程中,有 2n 节课程 ...

  5. 20180822-Java接口

    Java 接口 接口(英文:Interface),在JAVA编程语言中是一个抽象类型,是抽象方法的集合,接口通常以interface来声明.一个类通过继承接口的方式,从而来继承接口的抽象方法. 接口并 ...

  6. 学习日记14、EF 时间段查询

    m_Rep.GetList(a => System.Data.Entity.DbFunctions.DiffDays(DateTime.Now, a.EndDate) < date); 命 ...

  7. [CSP-S模拟测试]:赛(贪心+三分)

    题目描述 由于出题人思维枯竭所以想不出好玩的背景.有$n$个物品,第$i$个物品的价格是$v_i$,有两个人,每个人都喜欢$n$个物品中的一些物品.要求选出正好$m$个物品,满足选出的物品中至少有$k ...

  8. [CSP-S模拟测试]:可爱的精灵宝贝(搜索)

    题目描述 $Branimirko$是一个对可爱精灵宝贝十分痴迷的玩家.最近,他闲得没事组织了一场捉精灵的游戏.游戏在一条街道上举行,街道上一侧有一排房子,从左到右房子标号由$1$到$n$.刚开始玩家在 ...

  9. 【Pytest】python单元测试框架pytest简介

    1.Pytest介绍 pytest是python的一种单元测试框架,与python自带的unittest测试框架类似,但是比unittest框架使用起来更简洁,效率更高.根据pytest的官方网站介绍 ...

  10. hdu多校第二场1008(hdu6598) Harmonious Army 最小割

    题意: 一个军队有n人,你可以给他们每个人安排战士或者法师的职业,有m对人有组合技,组合技的信息是a,b,c,代表如果这两个人是两个战士,则组合技威力为a,一个战士一个法师,威力为b,其中b=a/4+ ...