admin 管理员组

文章数量: 887021


2024年2月20日发(作者:进程管理与处理机管理一样吗)

import ataSource;import ataSourceBuilder;import tatProperties;import ;import urceType;import roperties;import cDataSource;import Utils;import AsyncExecutor;import ProcessEngineConfiguration;import ctProcessEngineAutoConfiguration;import ionalOnProperty;import urationProperties;import RegistrationBean;import ;import uration;import y;import rmTransactionManager;import t.*;import urce;import ption;import p;import ;/** * druid 配置多数据源 * * @author xxx */@Configurationpublic class DruidConfig extends AbstractProcessEngineAutoConfiguration { @Bean @ConfigurationProperties("") public DataSource systemDataSource(DruidProperties druidProperties) { DruidDataSource dataSource = ().build(); return urce(dataSource); } @Bean @ConfigurationProperties("ti") @ConditionalOnProperty(prefix = "ti", name = "enabled", havingValue = "true") public DataSource activitiDataSource(DruidProperties druidProperties) { DruidDataSource dataSource = ().build(); return urce(dataSource); } @Bean @ConfigurationProperties("sm") @ConditionalOnProperty(prefix = "sm", name = "enabled", havingValue = "true") public DataSource allelismDataSource(DruidProperties druidProperties) { DruidDataSource dataSource = ().build(); return urce(dataSource); } @Bean @ConfigurationProperties("te") @ConditionalOnProperty(prefix = "te", name = "enabled", havingValue = "true") public DataSource templateDataSource(DruidProperties druidProperties) { DruidDataSource dataSource = ().build(); return urce(dataSource); }

@Bean @ConfigurationProperties("") @ConditionalOnProperty(prefix = "", name = "enabled", havingValue = "true") public DataSource logDataSource(DruidProperties druidProperties) { DruidDataSource dataSource = ().build(); return urce(dataSource); } @Bean @ConfigurationProperties("") @ConditionalOnProperty(prefix = "", name = "enabled", havingValue = "true") public DataSource eventDataSource(DruidProperties druidProperties) { DruidDataSource dataSource = ().build(); return urce(dataSource); } @Bean @ConfigurationProperties("") @ConditionalOnProperty(prefix = "", name = "enabled", havingValue = "true") public DataSource statisDataSource(DruidProperties druidProperties) { DruidDataSource dataSource = ().build(); return urce(dataSource); } @Bean(name = "dynamicDataSource") @Primary public DynamicDataSource dataSource(DataSource systemDataSource) { Map targetDataSources = new HashMap<>(); ((), systemDataSource); setDataSource(targetDataSources, (), "activitiDataSource"); setDataSource(targetDataSources, (), "allelismDataSource"); setDataSource(targetDataSources, (), "templateDataSource"); setDataSource(targetDataSources, (), "logDataSource"); setDataSource(targetDataSources, (), "eventDataSource"); setDataSource(targetDataSources, (), "statisDataSource"); return new DynamicDataSource(systemDataSource, targetDataSources); } /** * 设置数据源 * * @param targetDataSources 备选数据源集合 * @param sourceName 数据源名称 * @param beanName bean名称 */ public void setDataSource(Map targetDataSources, String sourceName, String beanName) { try { DataSource dataSource = n(beanName); (sourceName, dataSource); } catch (Exception e) { } } @Bean public SpringProcessEngineConfiguration springProcessEngineConfiguration( PlatformTransactionManager transactionManager, SpringAsyncExecutor springAsyncExecutor) throws IOException { return baseSpringProcessEngineConfiguration( n("activitiDataSource"), transactionManager, springAsyncExecutor); }

}讲解:ProceedingJoinPoint get().getClass();otation()获取当前注解动态数据源import ctRoutingDataSource;import urce;import ;/** * 动态数据源 * * @author xxx */public class DynamicDataSource extends AbstractRoutingDataSource{ public DynamicDataSource(DataSource defaultTargetDataSource, Map targetDataSources) { aultTargetDataSource(defaultTargetDataSource); getDataSources(targetDataSources); ropertiesSet(); } @Override protected Object determineCurrentLookupKey() { return aSourceType(); }}


本文标签: 数据源 管理 动态 进程 获取