Mybatis 搭建遇到的坑
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&useSSL=false"/>
注意 在xml中,
& : &
< : <
> : >
" : "
' : '
Mybatis 搭建遇到的坑的更多相关文章
- 记一次ftp服务器搭建走过的坑
记一次ftp服务器搭建走过的坑 1.安装 ①下载 wget https://security.appspot.com/downloads/vsftpd-3.0.3.tar.gz #要FQ ②解压 ta ...
- springboot +mybatis 搭建完整项目
springboot + mybatis搭建完整项目 1.springboot整合mybatis注解版 转:https://blog.csdn.net/u013187139/article/detai ...
- 使用idea+springboot+Mybatis搭建web项目
使用idea+springboot+Mybatis搭建web项目 springboot的优势之一就是快速搭建项目,省去了自己导入jar包和配置xml的时间,使用非常方便. 1.创建项目project, ...
- Linux系统搭建GitLab---阿里云Centos7搭建Gitlab踩坑
一.简介 GitLab,是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目安装. 它拥有与GitHub类似的功能,能 ...
- idea+springboot+Mybatis搭建web项目
使用idea+springboot+Mybatis搭建一个简单的web项目. 首先新建一个项目: 在这里选择Maven项目也可以,但是IDEA为我们提供了一种更方便快捷的创建方法,即Spring In ...
- springboot+mybatis搭建web项目
使用idea+springboot+Mybatis搭建一个简单的web项目. 首先新建一个项目: 在这里选择Maven项目也可以,但是IDEA为我们提供了一种更方便快捷的创建方法,即Spring In ...
- spring boot+mybatis搭建项目
一.创建spring boot项目 1.File->New->Project 2.选择 Spring Initializr ,然后选择默认的 url 点击[Next]: 3.修改项目信息 ...
- elasticsearch 单节点搭建与爬坑记录
elasticsearch 单节点搭建与爬坑记录 prepare 虚拟机或者云服务器(这里用的是阿里云ECS) linux---centos7 安装完毕的jdk 相应的安装包(在https:/ ...
- Mybatis的失误填坑-java.lang.Integer cannot be cast to java.lang.String
Mybatis的CRUD小Demo 为方便查看每次的增删改结果,封装了查询,用来显示数据库的记录: public static void showInfo(){ SqlSession session ...
随机推荐
- WAR包方式安装Jenkins
WAR包方式安装Jenkins 系统环境: CentOS 7.5 1804 IP:192.168.1.3 关闭selinux.firewalld jenkins war包:下载地址 一.安装t ...
- Windows下静态库与动态库的创建与使用
Windows下静态库与动态库的创建与使用 学习内容:本博客介绍了Windows下使用Visual C++ 6.0制作与使用静态库与动态库的方法. --------CONTENTS-------- 一 ...
- Spring Boot 的 application.properties
更改默认端口:8080 server.port = 8081 更改context-path :/server.context-path = /springboot #server.address= # ...
- python split()函数的用法
转自: https://blog.csdn.net/orangefly0214/article/details/80810449 函数:split() Python中有split()和os.path. ...
- 记录在tiny6410平台上采用4GSD卡来启动uboot和烧写nand flash uboot
下面这种方法是从网上转的 没有验证 环境:ubuntu 13.04一.首先制作sd启动盘: 插入SD卡 sudo dd iflag=dsync oflag=dsync if=tiny210v2- ...
- WIFI CAT ET III Adapter Caterpillar ET3 New Arrival
The old bluetooth cat et adatper iii has stopped production, and you can get the new WIFI CAT Caterp ...
- docker启动后忘记挂载nvidia-docker-volume的解决方法
进入 docker 目录 删除 volumes 下的所有文件 重新启动docker 运行nvidia-docker run XXX 来生成volume 修改所有 docker目录下containers ...
- jmeter插件使用说明
jmeter作为一个开源的接口性能测试工具,其本身的小巧和灵活性给了测试人员很大的帮助,但其本身作为一个开源工具,相比于一些商业工具(比如LoadRunner),在功能的全面性上就稍显不足. 这篇博客 ...
- flutter 常用插件
audio_recorder: any #录音.播放 flutter_sound: ^1.1.5#录音 dropdown_menu: ^1.1.0#下拉菜单 simple_permissions:#权 ...
- sqlalchemy orm介绍
ORM介绍 简解:用户会使用ORM时会直接访问对象,对象在通过ORM与数据库进行交互,不需要用户操作sql. 详解:orm英文全称object relational mapping,就是对象映射关系程 ...