当前位置:网站首页>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);
}
}
修改完之后再次启动测试
可以看到日志信息已经在创建表了
查看数据库 表已经正常创建
边栏推荐
- [API interface tool] Introduction to postman interface
- 模拟卷Leetcode【普通】1249. 移除无效的括号
- 模拟卷Leetcode【普通】1061. 按字典序排列最小的等效字符串
- Testing of web interface elements
- JWT-JSON WEB TOKEN
- The latest 2022 review of "graph classification research"
- 【C语言】字符串左旋
- LeetCode 732. 我的日程安排表 III
- Simulation volume leetcode [general] 1218 Longest definite difference subsequence
- win10无法操作(删除、剪切)文件
猜你喜欢
随机推荐
Online and offline problems
黑猫带你学UFS协议第4篇:UFS协议栈详解
LeetCode 1200. 最小绝对差
浅谈专项测试之弱网络测试
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Caused by:org.gradle.api.internal.plugins . PluginApplicationException: Failed to apply plugin
Postman核心功能解析-参数化和测试报告
Digital triangle model acwing 1015 Picking flowers
模拟卷Leetcode【普通】1143. 最长公共子序列
Resttemplate and feign realize token transmission
An article was uncovered to test the truth of outsourcing companies
Isam2 and incrementalfixedlagsmooth instructions in gtsam
How to extract login cookies when JMeter performs interface testing
【API接口工具】postman-界面使用介绍
The latest 2022 review of "graph classification research"
【Postman】测试(Tests)脚本编写和断言详解
MFC on the conversion and display of long string unsigned char and CString
Technology sharing | common interface protocol analysis
技术分享 | 常见接口协议解析
Application of Lie group in gtsam