当前位置:网站首页>Avtiviti创建表时报错:Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException
Avtiviti创建表时报错:Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException
2022-07-06 06:19:00 【不允许摆烂】
问题描述
今天使用Acitivity创建ProcessEngineConfiguration对象时报错
错误如下


org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)
### Error getting a new connection. Cause: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)
### Cause: org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Could not create connection to database server.)
分析问题
1 有可能是mysql版本驱动的问题
2 有可能是配置错误问题
3 经我测试和查询网上的相关错误,大部分原因都是mysql版本问题或者配置错误,比如url确实参数,驱动8.0少加了cj,我是因为版本问题,我本地是8.0的数据库,但是jar是5.7的
解决问题
相关代码如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.wyh</groupId>
<artifactId>Activiti01</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<activiti.version>6.0.0</activiti.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.activiti</groupId>
<artifactId>activiti-spring-boot-starter-rest-api</artifactId>
<version>${
activiti.version}</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
配置
<?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:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/contex
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
<!--dbcp链接池-->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql:///activiti?serverTimezone=UTC"/>
<property name="username" value="root"/>
<property name="password" value="root"/>
<property name="maxActive" value="3"/>
<property name="maxIdle" value="1"/>
</bean>
<!--在默认方式下 bean的id 固定为 processEngineConfiguration-->
<bean id="processEngineConfiguration"
class="org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration">
<!--配置数据库相关的信息-->
<!--数据库驱动
<property name="jdbcDriver" value="com.mysql.jdbc.Driver"/>-->
<!--数据库链接
<property name="jdbcUrl" value="jdbc:mysql:///activiti"/>-->
<!--数据库用户名
<property name="jdbcUsername" value="root"/>-->
<!--数据库密码
<property name="jdbcPassword" value="123456"/>-->
<!--直接引用上面配置的链接池-->
<property name="dataSource" ref="dataSource"/>
<!--actviti数据库表在生成时的策略
true - 如果数据库中已经存在相应的表,那么直接使用,
如果不存在,那么会创建-->
<property name="databaseSchemaUpdate" value="true"/>
</bean>
</beans>
测试类
package com.wyh.test;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.junit.Test;
/** * @program: Activiti01 * @description: * @author: 魏一鹤 * @createDate: 2022-06-22 21:59 **/
public class TestCreateTable {
/** * 使用activiti提供的默认方式来创建mysql的表 */
@Test
public void testCreateDbTable(){
// 需要使用avtiviti提供的工具类 ProcessEngines ,使用方法getDefaultProcessEngine
// getDefaultProcessEngine会默认从resources下读取名字为actviti.cfg.xml的文件
// 创建processEngine时,就会创建mysql的表
ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
System.out.println(processEngine);
}
}
修改完之后再次启动测试
可以看到日志信息已经在创建表了
查看数据库 表已经正常创建
边栏推荐
- Detailed explanation of P problem, NP problem, NPC problem and NP hard problem
- 黑猫带你学UFS协议第18篇:UFS如何配置逻辑单元(LU Management)
- 技术分享 | 常见接口协议解析
- F - True Liars (种类并查集+DP)
- 曼哈顿距离与曼哈顿矩形-打印回字型矩阵
- 模拟卷Leetcode【普通】1414. 和为 K 的最少斐波那契数字数目
- The pit encountered by keil over the years
- 【eolink】PC客户端安装
- G - Supermarket
- 黑猫带你学eMMC协议第10篇:eMMC读写操作详解(read & write)
猜你喜欢
随机推荐
oscp raven2靶机渗透过程
Manhattan distance sum - print diamond
Simulation volume leetcode [general] 1061 Arrange the smallest equivalent strings in dictionary order
LeetCode 731. 我的日程安排表 II
GTSAM中ISAM2和IncrementalFixedLagSmoother说明
[postman] collections configuration running process
模拟卷Leetcode【普通】1414. 和为 K 的最少斐波那契数字数目
数字三角形模型 AcWing 1015. 摘花生
在线问题与离线问题
私人云盘部署
Overview of three core areas of Mathematics: algebra
【微信小程序】搭建开发工具环境
Isam2 operation process
Career advancement Guide: recommended books for people in big factories
leetcode 24. Exchange the nodes in the linked list in pairs
模拟卷Leetcode【普通】1219. 黄金矿工
(中)苹果有开源,但又怎样呢?
Digital triangle model acwing 1015 Picking flowers
Simulation volume leetcode [general] 1249 Remove invalid parentheses
php使用redis实现分布式锁









