近期公司的項目在做國產(chǎn)化兼容椰憋,數(shù)據(jù)庫方面試了下國產(chǎn)達夢數(shù)據(jù)庫腕唧,踩了不少坑或辖。。
項目使用SpringBoot 2.2.6+Mybatis四苇,工作流使用Flowable 6.4.2孝凌,連接池使用Druid
配置文件
pom.xml中引入驅(qū)動jar包(可在達夢安裝目錄中找到)
<!--達夢數(shù)據(jù)庫-->
<dependency>
<groupId>com.dm</groupId>
<artifactId>dmjdbc8</artifactId>
<version>1.8</version>
<scope>system</scope>
<systemPath>${pom.basedir}/lib/DmJdbcDriver18.jar</systemPath>
</dependency>
application.properties中對應(yīng)修改
#******達夢******
spring.datasource.driver-class-name=dm.jdbc.driver.DmDriver
spring.datasource.url=jdbc:dm://127.0.0.1:5236/SYSDBA
spring.datasource.username=SYSDBA
spring.datasource.password=123456789
#達夢數(shù)據(jù)庫不支持此項
#spring.datasource.druid.filters=stat,wall
#pagehelper使用mysql語法
pagehelper.helper-dialect=mysql
#mybatis設(shè)置database-id
mybatis.configuration.database-id=dm
#達夢數(shù)據(jù)庫關(guān)閉flowable自動更新數(shù)據(jù)庫結(jié)構(gòu)
flowable.database-schema-update=false
Flowable修改
上面設(shè)置完成后嘗試啟動項目,報錯信息如下:
Caused by: org.flowable.common.engine.api.FlowableException: couldn't deduct database type from database product name 'DM DBMS'
at org.flowable.common.engine.impl.AbstractEngineConfiguration.initDatabaseType(AbstractEngineConfiguration.java:282)
at org.flowable.common.engine.impl.AbstractEngineConfiguration.initDataSource(AbstractEngineConfiguration.java:252)
at org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl.init(ProcessEngineConfigurationImpl.java:951)
at org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:915)
at org.flowable.spring.SpringProcessEngineConfiguration.buildProcessEngine(SpringProcessEngineConfiguration.java:72)
at org.flowable.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:60)
at org.flowable.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:32)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171)
... 59 common frames omitted
flowable并不認識國產(chǎn)數(shù)據(jù)庫月腋,需要修改文件:
在項目中創(chuàng)建org.flowable.common.engine.impl.AbstractEngineConfiguration文件(這邊路徑必須一致,打包時會覆蓋源文件)瓣赂,修改其中getDefaultDatabaseTypeMappings方法榆骚,將達夢數(shù)據(jù)庫標識為mysql:
public static Properties getDefaultDatabaseTypeMappings() {
Properties databaseTypeMappings = new Properties();
databaseTypeMappings.setProperty("H2", "h2");
databaseTypeMappings.setProperty("HSQL Database Engine", "hsql");
databaseTypeMappings.setProperty("MySQL", "mysql");
databaseTypeMappings.setProperty("MariaDB", "mysql");
databaseTypeMappings.setProperty("Oracle", "oracle");
databaseTypeMappings.setProperty("PostgreSQL", "postgres");
databaseTypeMappings.setProperty("Microsoft SQL Server", "mssql");
databaseTypeMappings.setProperty("db2", "db2");
databaseTypeMappings.setProperty("DB2", "db2");
***此處省略***
databaseTypeMappings.setProperty("DM DBMS", "mysql");// 加入達夢支持
return databaseTypeMappings;
}
創(chuàng)建flowable數(shù)據(jù)庫
之前配置文件中關(guān)閉了數(shù)據(jù)庫自動生成更新,這是因為無論是把數(shù)據(jù)庫標識為 mysql 還是 oracle煌集,都無法自動生成妓肢。要么修改源碼中的生成語句并原路徑覆蓋,我這里是找到github上flowable源碼中的生成語句直接生成苫纤。
源碼目錄如下:
本項目引入的flowable模塊如下:
<!--Flowable工作流-->
<dependency>
<groupId>org.flowable</groupId>
<artifactId>flowable-spring-boot-starter-process</artifactId>
<version>${flowable.version}</version>
</dependency>
查看了下只需要復(fù)制三個模塊的語句并修改:
使用IDE工具一鍵替換一些關(guān)鍵詞:
一鍵刪除以下語句:
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE utf8_bin
一鍵替換以下關(guān)鍵詞:
LONGBLOB ===》 BLOB
auto_increment ===》identity
修改完成后碉钠,按順序執(zhí)行三個文件,即可生成flowable數(shù)據(jù)庫卷拘。
至此叁扫,項目應(yīng)該能正常啟動了
使用過程中的一些坑:
報錯1:
LINK 在達夢8中為關(guān)鍵詞仪糖,而flowable中Task.xml中確有用作別名:
#報錯相關(guān)語句
select LINK.ID_ from ACT_RU_IDENTITYLINK LINK
修改也很簡單,在resources目錄下,創(chuàng)建同路徑文件替換即可
注意:這邊和jar中的路徑不一樣蔫骂,并非在java目錄下,而是resources。我之前替換一直無效,直到下了源碼看了結(jié)構(gòu)才發(fā)現(xiàn)陆蟆。