1.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com">
<select id = "findById" parameterType="int" resultType="User">
SELECT * FROM Book WHERE id=#{id}
</select>
</mapper>

提示下面飘红不可用,导致在其他类里面引用:

import org.apache.ibatis.io.Resources;

import org.apache.ibatis.*,未能找到
我还以为是缺少jar ibatis ,在pom.xml中 配置ibatis也不能成功,花费了不少时间.
解决办法:
在 File->Settings->Schemas and DTDs 中配置不信任链接

2. SqlSession session = sqlMapper.openSession(); 获取不到session值,为null

@font-face{ font-family:"Times New Roman"; } @font-face{ font-family:"宋体"; } @font-face{ font-family:"Calibri"; } @font-face{ font-family:"SimSun"; } p.MsoNormal{ mso-style-name:Normal; mso-style-parent:""; margin:0pt; margin-bottom:.0001pt; font-family:Calibri; mso-fareast-font-family:SimSun; mso-bidi-font-family:'Times New Roman'; } span.msoIns{ mso-style-type:export-only; mso-style-name:""; text-decoration:underline; text-underline:single; color:blue; } span.msoDel{ mso-style-type:export-only; mso-style-name:""; text-decoration:line-through; color:red; } @page{mso-page-border-surround-header:no; mso-page-border-surround-footer:no;}@page Section0{ } div.Section0{page:Section0;}

Caused by: java.lang.NullPointerException

at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:95)

... 2 more

出错原因:
一开始按照教程操作,在配置mybatis-config.xml的时候 <environments default="development"> 调试发现session 为null,
找到这篇解释,出自: https://blog.csdn.net/u012972315/article/details/51725646
下面为引用内容:

后来查看mybatis文档才了解到,在mybatis配置时,可能由于我们开发时的数据库环境和最终上线时的数据库环境不同,因此可以在配置文件中配置多个数据库环境;
即在 < enviroments >标签下可以配置多个< enviroment>标签,每一个< enviroment >标签对应一个数据库环境
而不同的数据库环境通过< enviroment > 标签的 id 属性用以区分
那么具体开发时如果知道使用的是哪一个环境呢?
在< envirments> 标签里有一个default属性,该属性对应的是下面的不同的< enviroment > 的id属性
default的值为哪一个id,则代表此时使用的是哪一个environment数据库环境

解决办法: <environments default="book">,default= 需要使用数据库的id.
<!-- 对事务管理和连接池配置 -->
<environments default="book">
<environment id="book">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/gossip"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
</dataSource>
</environment>
</environments>
3.
WARN: Establishing SSL connection without server's identity verification is not recommended.
According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set.
For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'.
You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore
for server certificate verification.
出错原因:
mybatis-config.xml 配置中需要增加一句 &useSSL=false,
<property name="url" value="jdbc:mysql://localhost:3306/gossip?autoReconnect=true&amp;useSSL=false"/>
注意 在xml中,
& : &amp;
< : &lt;
> : &gt;
" : &quot;
' : &apos;

Mybatis 搭建遇到的坑的更多相关文章

  1. 记一次ftp服务器搭建走过的坑

    记一次ftp服务器搭建走过的坑 1.安装 ①下载 wget https://security.appspot.com/downloads/vsftpd-3.0.3.tar.gz #要FQ ②解压 ta ...

  2. springboot +mybatis 搭建完整项目

    springboot + mybatis搭建完整项目 1.springboot整合mybatis注解版 转:https://blog.csdn.net/u013187139/article/detai ...

  3. 使用idea+springboot+Mybatis搭建web项目

    使用idea+springboot+Mybatis搭建web项目 springboot的优势之一就是快速搭建项目,省去了自己导入jar包和配置xml的时间,使用非常方便. 1.创建项目project, ...

  4. Linux系统搭建GitLab---阿里云Centos7搭建Gitlab踩坑

    一.简介 GitLab,是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目安装. 它拥有与GitHub类似的功能,能 ...

  5. idea+springboot+Mybatis搭建web项目

    使用idea+springboot+Mybatis搭建一个简单的web项目. 首先新建一个项目: 在这里选择Maven项目也可以,但是IDEA为我们提供了一种更方便快捷的创建方法,即Spring In ...

  6. springboot+mybatis搭建web项目

    使用idea+springboot+Mybatis搭建一个简单的web项目. 首先新建一个项目: 在这里选择Maven项目也可以,但是IDEA为我们提供了一种更方便快捷的创建方法,即Spring In ...

  7. spring boot+mybatis搭建项目

    一.创建spring boot项目 1.File->New->Project 2.选择 Spring Initializr ,然后选择默认的 url 点击[Next]: 3.修改项目信息 ...

  8. elasticsearch 单节点搭建与爬坑记录

    elasticsearch 单节点搭建与爬坑记录   prepare   虚拟机或者云服务器(这里用的是阿里云ECS) linux---centos7 安装完毕的jdk 相应的安装包(在https:/ ...

  9. Mybatis的失误填坑-java.lang.Integer cannot be cast to java.lang.String

    Mybatis的CRUD小Demo 为方便查看每次的增删改结果,封装了查询,用来显示数据库的记录: public static void showInfo(){ SqlSession session ...

随机推荐

  1. Spring框架的第三天

    ## Spring框架的第三天 ## ---------- **课程回顾:Spring框架第二天** 1. IOC的注解方式 * @Value * @Resource(name="" ...

  2. NOIP2012借教室

    题目描述 Description 在大学期间,经常需要租借教室.大到院系举办活动,小到学习小组自习讨论,都需要 向学校申请借教室.教室的大小功能不同,借教室人的身份不同,借教室的手续也不一样. 面对海 ...

  3. InternalError (see above for traceback): Blas GEMV launch failed: m=1, n=100

    python tensorflow 运行提示错误:InternalError (see above for traceback): Blas GEMV launch failed:  m=1, n=1 ...

  4. Flip Game (高斯消元 || dfs)

    Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 square ...

  5. 记录Ok6410 sd 启动uboot

    1\参考资料https://github.com/SeanXP/ARM-Tiny6410/tree/master/no-os/sd-no-os/u-boot 2\参考资料https://blog.cs ...

  6. <转>jmeter(二十二)内存溢出原因及解决方法

    本博客转载自:http://www.cnblogs.com/imyalost/category/846346.html 个人感觉不错,对jmeter讲解非常详细,担心以后找不到了,所以转发出来,留着慢 ...

  7. jQuery 查找元素2

    jQuery 查找元素2 :first <ul> <li>list item 1</li> <li>list item 2</li> < ...

  8. opencv学习之路(28)、轮廓查找与绘制(七)——位置关系及轮廓匹配

    一.点与轮廓的距离及位置关系 #include "opencv2/opencv.hpp" #include <iostream> using namespace std ...

  9. 第十届蓝桥杯2019年C/C++ 大学B组省赛试题

    2019年第十届蓝桥杯大赛软件类省赛C/C++大学B组 试题 A:组队 本题总分:5分 [问题描述] 作为篮球队教练,你需要从以下名单中选出 1号位至 5号位各一名球员, 组成球队的首发阵容. 每位球 ...

  10. 在新获取git中项目时出现的问题汇总

    新下拉git项目,今天遇到的问题,因为刚配置实用jdk和idea,所以有可能在打开springboot项目时查看mysql数据库驱动显示为红色. 之后看到pom文件也没有错,最后发现才是在项目中还没有 ...