1|1簡介
成都創(chuàng)新互聯(lián)是一家專注于成都網(wǎng)站制作、成都網(wǎng)站建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)與策劃設(shè)計(jì),全州網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設(shè)10多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專業(yè)建站公司;建站業(yè)務(wù)涵蓋:全州等地區(qū)。全州做網(wǎng)站價(jià)格咨詢:18982081108
最近基于最新的Activiti7配置了SpringBoot2。
簡單上手使用了一番。發(fā)現(xiàn)市面上解決Activiti7的教程很少,采坑也比較多,在Activiti6配置數(shù)據(jù)源和Activiti7有所區(qū)別,基于Activiti6在Activiti7里是無法正常使用的。接下來讓我們看下區(qū)別。
1|2問題
Activiti6多數(shù)據(jù)源配置
6的配置比較簡單點(diǎn)。
先加入配置:
# activiti 數(shù)據(jù)源 spring.datasource.activiti.driver=com.MySQL.jdbc.Driver spring.datasource.activiti.url=jdbc:mysql://10.1.1.97:3311/test-activiti7-db?useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true spring.datasource.activiti.username=root spring.datasource.activiti.password=Rtqw123OpnmER spring.datasource.activiti.driverClassName=com.mysql.jdbc.Driver
@Configuration public class ActivitiConfig extends AbstractProcessEngineAutoConfiguration { @Bean @ConfigurationProperties(prefix = "spring.datasource.activiti") public DataSource activitiDataSource() { return DataSourceBuilder.create().build(); } @Bean public SpringProcessEngineConfiguration springProcessEngineConfiguration( PlatformTransactionManager transactionManager, SpringAsyncExecutor springAsyncExecutor) throws IOException { return baseSpringProcessEngineConfiguration( activitiDataSource(), transactionManager, springAsyncExecutor); } }
Activiti6的數(shù)據(jù)源已經(jīng)配置完成,如果是7的話會(huì)發(fā)現(xiàn)
AbstractProcessEngineAutoConfiguration#baseSpringProcessEngineConfiguration
方法已經(jīng)不存在了,我們需要產(chǎn)考源碼構(gòu)建方式改造一番。
1|3修復(fù)
Activiti7多數(shù)據(jù)源配置
配置還是要上面的。
@Configuration public class ActivitiConfig extends AbstractProcessEngineAutoConfiguration { @Bean @ConfigurationProperties(prefix = "spring.datasource.activiti") public DataSource activitiDataSource() { return DataSourceBuilder.create().build(); } ...略 } SpringProcessEngineConfiguration注入方式改為下面: @Bean @Primary public SpringProcessEngineConfiguration springProcessEngineConfiguration( PlatformTransactionManager transactionManager, SpringAsyncExecutor springAsyncExecutor, ActivitiProperties activitiProperties, ProcessDefinitionResourceFinder processDefinitionResourceFinder, @Autowired(required = false) DefaultActivityBehaviorFactoryMappingConfigurer processEngineConfigurationConfigurer, @Autowired(required = false) List<ProcessEngineConfigurator> processEngineConfigurators, UserGroupManager userGroupManager, DataSource dataSource) throws IOException { SpringProcessEngineConfiguration conf = new SpringProcessEngineConfiguration(); conf.setConfigurators(processEngineConfigurators); configureProcessDefinitionResources(processDefinitionResourceFinder, conf); conf.setDataSource(dataSource); conf.setTransactionManager(transactionManager); if (springAsyncExecutor != null) { conf.setAsyncExecutor(springAsyncExecutor); } conf.setDeploymentName(activitiProperties.getDeploymentName()); conf.setDatabaseSchema(activitiProperties.getDatabaseSchema()); conf.setDatabaseSchemaUpdate(activitiProperties.getDatabaseSchemaUpdate()); conf.setDbHistoryUsed(activitiProperties.isDbHistoryUsed()); conf.setAsyncExecutorActivate(activitiProperties.isAsyncExecutorActivate()); if (!activitiProperties.isAsyncExecutorActivate()) { ValidatorSet springBootStarterValidatorSet = new ValidatorSet("activiti-spring-boot-starter"); springBootStarterValidatorSet.addValidator(new AsyncPropertyValidator()); if (conf.getProcessValidator() == null) { ProcessValidatorImpl processValidator = new ProcessValidatorImpl(); processValidator.addValidatorSet(springBootStarterValidatorSet); conf.setProcessValidator(processValidator); } else { conf.getProcessValidator().getValidatorSets().add(springBootStarterValidatorSet); } } conf.setMailServerHost(activitiProperties.getMailServerHost()); conf.setMailServerPort(activitiProperties.getMailServerPort()); conf.setMailServerUsername(activitiProperties.getMailServerUserName()); conf.setMailServerPassword(activitiProperties.getMailServerPassword()); conf.setMailServerDefaultFrom(activitiProperties.getMailServerDefaultFrom()); conf.setMailServerUseSSL(activitiProperties.isMailServerUseSsl()); conf.setMailServerUseTLS(activitiProperties.isMailServerUseTls()); if (userGroupManager != null) { conf.setUserGroupManager(userGroupManager); } conf.setHistoryLevel(activitiProperties.getHistoryLevel()); conf.setCopyVariablesToLocalForTasks(activitiProperties.isCopyVariablesToLocalForTasks()); conf.setSerializePOJOsInVariablesToJson(activitiProperties.isSerializePOJOsInVariablesToJson()); conf.setJavaClassFieldForJackson(activitiProperties.getJavaClassFieldForJackson()); if (activitiProperties.getCustomMybatisMappers() != null) { conf.setCustomMybatisMappers( getCustomMybatisMapperClasses(activitiProperties.getCustomMybatisMappers())); } if (activitiProperties.getCustomMybatisXMLMappers() != null) { conf.setCustomMybatisXMLMappers( new HashSet<>(activitiProperties.getCustomMybatisXMLMappers())); } if (activitiProperties.getCustomMybatisXMLMappers() != null) { conf.setCustomMybatisXMLMappers( new HashSet<>(activitiProperties.getCustomMybatisXMLMappers())); } if (activitiProperties.isUseStrongUuids()) { conf.setIdGenerator(new StrongUuidGenerator()); } if (activitiProperties.getDeploymentMode() != null) { conf.setDeploymentMode(activitiProperties.getDeploymentMode()); } conf.setActivityBehaviorFactory(new DefaultActivityBehaviorFactory()); if (processEngineConfigurationConfigurer != null) { processEngineConfigurationConfigurer.configure(conf); } return conf; } private void configureProcessDefinitionResources( ProcessDefinitionResourceFinder processDefinitionResourceFinder, SpringProcessEngineConfiguration conf) throws IOException { List<Resource> procDefResources = processDefinitionResourceFinder .discoverProcessDefinitionResources(); if (!procDefResources.isEmpty()) { conf.setDeploymentResources(procDefResources.toArray(new Resource[0])); } }
1|4常見錯(cuò)誤
在以上配置中可能會(huì)有jdbcUrl is required with driverClassName錯(cuò)誤
解決辦法如下:
# activiti 數(shù)據(jù)源 spring.datasource.activiti.driver=com.mysql.jdbc.Driver spring.datasource.activiti.url=jdbc:mysql://10.1.1.97:3311/test-activiti7-db?useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=true # url換為jdbc-url 解決jdbcUrl is required with driverClassName錯(cuò)誤 # 官方文檔的解釋是: # 因?yàn)檫B接池的實(shí)際類型沒有被公開,所以在您的自定義數(shù)據(jù)源的元數(shù)據(jù)中沒有生成密鑰,而且在IDE中沒有完成(因?yàn)镈ataSource接口沒有暴露屬性)。 # 另外,如果您碰巧在類路徑上有Hikari,那么這個(gè)基本設(shè)置就不起作用了,因?yàn)镠ikari沒有url屬性(但是確實(shí)有一個(gè)jdbcUrl屬性)。在這種情況下,您必須重寫您的配置如下: spring.datasource.activiti.jdbc-url=${spring.datasource.activiti.url} spring.datasource.activiti.username=root spring.datasource.activiti.password=Rtqw123OpnmER spring.datasource.activiti.driverClassName=com.mysql.jdbc.Driver
1|5總結(jié)
Activiti7國內(nèi)的教程不是很多,需要自己在社區(qū)里或者官方文檔,源碼去看了解,細(xì)心學(xué)習(xí)。
示例代碼地址:activiti-starter
總結(jié)
以上所述是小編給大家介紹的解決Springboot2.1.x配置Activiti7單獨(dú)數(shù)據(jù)源問題,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)創(chuàng)新互聯(lián)網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
名稱欄目:解決Springboot2.1.x配置Activiti7單獨(dú)數(shù)據(jù)源問題
網(wǎng)頁路徑:http://jinyejixie.com/article0/gdpcoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App設(shè)計(jì)、服務(wù)器托管、移動(dòng)網(wǎng)站建設(shè)、、動(dòng)態(tài)網(wǎng)站、網(wǎng)站策劃
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)