亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何解決Springboot2.1.x配置Activiti7單獨數據源問題

發布時間:2021-08-03 10:04:00 來源:億速云 閱讀:136 作者:chen 欄目:編程語言

本篇內容介紹了“如何解決Springboot2.1.x配置Activiti7單獨數據源問題”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

1|1簡介

最近基于最新的Activiti7配置了SpringBoot2。

簡單上手使用了一番。發現市面上解決Activiti7的教程很少,采坑也比較多,在Activiti6配置數據源和Activiti7有所區別,基于Activiti6在Activiti7里是無法正常使用的。接下來讓我們看下區別。

1|2問題

Activiti6多數據源配置

6的配置比較簡單點。

先加入配置:

# activiti 數據源spring.datasource.activiti.driver=com.mysql.jdbc.Driverspring.datasource.activiti.url=jdbc:mysql://10.1.1.97:3311/test-activiti7-db?useUnicode=true&characterEncoding=utf8&useSSL=false&allowMultiQueries=truespring.datasource.activiti.username=rootspring.datasource.activiti.password=Rtqw123OpnmERspring.datasource.activiti.driverClassName=com.mysql.jdbc.Driver

用@ConfigurationProperties加載以spring.datasource.activiti開頭的DataSource。  創建ActivitiConfig繼承AbstractProcessEngineAutoConfiguration方法注入SpringProcessEngineConfigurationbean,調用AbstractProcessEngineAutoConfiguration#baseSpringProcessEngineConfiguration方法把創建的數據源注入。

@Configurationpublic 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的數據源已經配置完成,如果是7的話會發現

AbstractProcessEngineAutoConfiguration#baseSpringProcessEngineConfiguration方法已經不存在了,我們需要產考源碼構建方式改造一番。

1|3修復

Activiti7多數據源配置

配置還是要上面的。

創建ActivitiConfig繼承AbstractProcessEngineAutoConfiguration方法注入SpringProcessEngineConfigurationbean。  用@ConfigurationProperties加載以spring.datasource.activiti開頭的DataSource

@Configurationpublic 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常見錯誤

在以上配置中可能會有jdbcUrl is required with driverClassName錯誤

解決辦法如下:

# activiti 數據源spring.datasource.activiti.driver=com.mysql.jdbc.Driverspring.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錯誤# 官方文檔的解釋是:# 因為連接池的實際類型沒有被公開,所以在您的自定義數據源的元數據中沒有生成密鑰,而且在IDE中沒有完成(因為DataSource接口沒有暴露屬性)。# 另外,如果您碰巧在類路徑上有Hikari,那么這個基本設置就不起作用了,因為Hikari沒有url屬性(但是確實有一個jdbcUrl屬性)。在這種情況下,您必須重寫您的配置如下:spring.datasource.activiti.jdbc-url=${spring.datasource.activiti.url}spring.datasource.activiti.username=rootspring.datasource.activiti.password=Rtqw123OpnmERspring.datasource.activiti.driverClassName=com.mysql.jdbc.Driver

“如何解決Springboot2.1.x配置Activiti7單獨數據源問題”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

永德县| 滦南县| 西藏| 宁陕县| 阜康市| 仁怀市| 雷州市| 新兴县| 德庆县| 花莲市| 柯坪县| 南漳县| 吴忠市| 项城市| 新巴尔虎左旗| 张家港市| 昌邑市| 太仓市| 双鸭山市| 隆安县| 固安县| 慈利县| 鸡泽县| 阳朔县| 溧阳市| 额敏县| 台北市| 正阳县| 连江县| 惠安县| 汝阳县| 鹿邑县| 杨浦区| 区。| 唐山市| 苗栗县| 金华市| 宜兰县| 沐川县| 周口市| 泸西县|