原创:mysql5 还原至mysql 8.0.11数据库链接配置提示错误改有三:
a) mysql 连接jar包版修改 b)类路径修改 c)配置连接池地址修改
因版本升级,首先要修改
1:mysql-connector-java 架包版本修改
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId>
!--原版本 5.1.6--> <version>8.0.11</version> </dependency>
2:因架包升级至mysql8.0.11
mybatis的配置文件applicationContext-dao.xml
中有两处修改
a): 修改类路径 :
处理:提示信息表明数据库驱动com.mysql.jdbc.Driver‘已经被弃用了、应当使用新的驱动com.mysql.cj.jdbc.Driver‘
<property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/>
a): 加接地址url :
<property name="url" value="jdbc:mysql://localhost:3306/maven?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false"/>
所以,按照提示更改jdbc.properties配置 .com.mysql.jdbc.Driver 改为 com.mysql.cj.jdbc.Driver
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> <!--dao层配置文件开始--> <!--配置连接池--> <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"> <!--<property name="driverClassName" value="com.mysql.jdbc.Driver"/>--> <property name="driverClassName" value="com.mysql.cj.jdbc.Driver"/> <property name="url" value="jdbc:mysql://localhost:3306/maven?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&useSSL=false"/> <property name="username" value="root"/> <property name="password" value="root"/> </bean> <!--配置生产SqlSession对象的工厂--> <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <!--扫描pojo包,给包下所有pojo对象起别名--> <property name="typeAliasesPackage" value="com.itheima.domain"/> </bean> <!--扫描接口包路径,生成包下所有接口的代理对象,并且放入spring容器中--> <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer"> <property name="basePackage" value="com.itheima.dao"/> </bean> <!--dao层配置文件结束--> </beans>
原文地址:https://www.cnblogs.com/asplover/p/12347994.html
时间: 2024-09-29 22:59:54