当前位置: 首页 > news >正文

springboot 双数据源配置

1:pom

<!--SpringBoot启动依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>test</scope></dependency><!--集成mysql数据库--><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.26</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId><version>2.6.1</version></dependency><!--spring boot集成mybatis的依赖--><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>2.1.0</version></dependency><dependency><groupId>com.alibaba</groupId><artifactId>druid</artifactId><version>1.1.23</version></dependency><!-- fastjson --><dependency><groupId>com.alibaba</groupId><artifactId>fastjson</artifactId><version>2.0.23</version></dependency>

2:yml 配置

spring:application:name: activiti-workflowdatasource:url: jdbc:mysql://127.0.0.1:3306/item-centerurl.activiti: jdbc:mysql://127.0.0.1:3306/activitiusername: rootpassword: roottype: com.alibaba.druid.pool.DruidDataSource

3:DBConfig


package com.ikeeper.config;import com.alibaba.druid.pool.DruidDataSource;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;import javax.sql.DataSource;@Configuration
@MapperScan(basePackages  = DBConfig.PACKAGE , sqlSessionFactoryRef = "itemcenterSqlSessionFactory")
public class DBConfig {// 精确到 itemcenter 目录,以便跟其他数据源隔离static final String PACKAGE = "com.ikeeper.mapper.itemcenter";private static final String MAPPER_LOCATION = "classpath*:mybatis-mapper/itemcenter/*.xml";private static final String DOMAIN_PACKAGE = "com.ikeeper.entity";@Value("${spring.datasource.url}")private String dbUrl;@Value("${spring.datasource.username}")private String username;@Value("${spring.datasource.password}")private String password;//    @Value("${spring.datasource.driverClassName}")
//    private String driverClassName;@Bean(name="itemcenterDataSource")   //声明其为Bean实例public DataSource itemcenterDataSource() {DruidDataSource datasource = new DruidDataSource();datasource.setUrl(this.dbUrl);datasource.setUsername(username);datasource.setPassword(password);
//        datasource.setDriverClassName(driverClassName);return datasource;}@Bean(name = "itemcenterTransactionManager")public DataSourceTransactionManager itemcenterTransactionManager() {return new DataSourceTransactionManager(itemcenterDataSource());}@Bean(name = "itemcenterSqlSessionFactory")public SqlSessionFactory itemcenterSqlSessionFactory(@Qualifier("itemcenterDataSource") DataSource itemcenterDataSource)throws Exception {final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();sessionFactory.setDataSource(itemcenterDataSource);sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MAPPER_LOCATION));sessionFactory.setTypeAliasesPackage(DOMAIN_PACKAGE);//mybatis 数据库字段与实体类属性驼峰映射配置sessionFactory.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);return sessionFactory.getObject();}}

package com.ikeeper.config;import com.alibaba.druid.pool.DruidDataSource;
import org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration;
import org.activiti.spring.SpringProcessEngineConfiguration;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;import javax.sql.DataSource;@Configuration
@MapperScan(basePackages  = ActivitiDBConfig.PACKAGE , sqlSessionFactoryRef = "activitiSqlSessionFactory")
public class ActivitiDBConfig {// 精确到 activiti 目录,以便跟其他数据源隔离static final String PACKAGE = "com.ikeeper.mapper.activiti";private static final String MAPPER_LOCATION = "classpath*:mybatis-mapper/activiti/*.xml";private static final String DOMAIN_PACKAGE = "com.ikeeper.entity";@Value("${spring.datasource.url.activiti}")private String dbUrl;@Value("${spring.datasource.username}")private String username;@Value("${spring.datasource.password}")private String password;//    @Value("${spring.datasource.driverClassName}")
//    private String driverClassName;@Bean(name="activitiDataSource")   //声明其为Bean实例public DataSource activitiDataSource() {DruidDataSource datasource = new DruidDataSource();datasource.setUrl(this.dbUrl);datasource.setUsername(username);datasource.setPassword(password);
//        datasource.setDriverClassName(driverClassName);return datasource;}@Bean(name = "activitiTransactionManager")public DataSourceTransactionManager activitiTransactionManager() {return new DataSourceTransactionManager(activitiDataSource());}@Bean(name = "activitiSqlSessionFactory")public SqlSessionFactory activitiSqlSessionFactory(@Qualifier("activitiDataSource") DataSource activitiDataSource)throws Exception {final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();sessionFactory.setDataSource(activitiDataSource);sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MAPPER_LOCATION));sessionFactory.setTypeAliasesPackage(DOMAIN_PACKAGE);//mybatis 数据库字段与实体类属性驼峰映射配置sessionFactory.getObject().getConfiguration().setMapUnderscoreToCamelCase(true);return sessionFactory.getObject();}@Beanpublic SpringProcessEngineConfiguration processEngineConfiguration(){SpringProcessEngineConfiguration standaloneProcessEngineConfiguration = new SpringProcessEngineConfiguration();standaloneProcessEngineConfiguration.setDatabaseSchemaUpdate("true");standaloneProcessEngineConfiguration.setDataSource(activitiDataSource());standaloneProcessEngineConfiguration.setTransactionManager(activitiTransactionManager());return standaloneProcessEngineConfiguration;}
}

3:目录

相关文章:

springboot 双数据源配置

1:pom <!--SpringBoot启动依赖--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</group…...

Redis内存使用率高,内存不足问题排查和解决

问题现象 表面现象是系统登录突然失效&#xff0c;排查原因发现&#xff0c;使用redis查询用户信息异常&#xff0c;从而定位到redis问题 if (PassWord.equals(dbPassWord)) {map.put("rtn", 1);map.put("value", validUser);session.setAttribute("…...

bootstrap5开发房地产代理公司Hamilton前端页面

一、需求分析 房地产代理网站是指专门为房地产行业提供服务的在线平台。这些网站的主要功能是连接房地产中介机构、房产开发商和潜在的买家或租户&#xff0c;以促成买卖或租赁房产的交易。以下是一些常见的房地产代理网站的功能&#xff1a; 房源发布&#xff1a;房地产代理网…...

2024年Mac专用投屏工具AirServer 7 .27 for Mac中文版

AirServer 7 .27 for Mac中文免费激活版是一款Mac专用投屏工具&#xff0c;能够通过本地网络将音频、照片、视频以及支持AirPlay功能的第三方App&#xff0c;从 iOS 设备无线传送到 Mac 电脑的屏幕上&#xff0c;把Mac变成一个AirPlay终端的实用工具。 目前最新的AirServer 7.2…...

关于MySql字段类型的实践总结

当字段为数值类型时应使用无符号UNSIGNED修饰 ALTER TABLE infoMODIFY COLUMN user_id int UNSIGNED NOT NULL; 当字段为varchar类型时应注意是否选择合适的字符集 例如存储一些范围值&#xff0c;数字英文字符时&#xff08;IP、生日、客户端标识等或以“,”分隔的数据&…...

UG NX二次开发(C#)-Ufun和NXOpen混合编程

提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 1、前言2、Ufun函数3、 NXOpen4、混合编程实现1、前言 在UG NX二次开发过程中,采用Ufun功能比较简单,能用比较少的代码实现我们需要的功能,但是ufun函数的功能不是很强大,尤其随着UG NX的版本…...

【Spark精讲】一文讲透Spark RDD

MapReduce的缺陷 MR虽然在编程接口的种类和丰富程度上已经比较完善了&#xff0c;但这些系统普遍都缺乏操作分布式内存的接口抽象&#xff0c;导致很多应用在性能上非常低效 。 这些应用的共同特点是需要在多个并行操 作之间重用工作数据集 &#xff0c;典型的场景就是机器学习…...

如在MT9040、IDT82V3001A 等锁相环上电后或输入参考频率改变后必须复位锁相环。

锁相环是一种反馈控制系统,它能够将输出信号的相位锁定到输入参考信号的相位上。在实际应用中,如MT9040、IDT82V3001A等PLL集成电路在上电后或者当输入参考频率发生变化后通常需要复位的原因涉及到几个方面: 1、初始化状态: 当PLL电路上电时,其内部的各个组件可能…...

构建安全的SSH服务体系

某公司的电子商务站点由专门的网站管理员进行配置和维护&#xff0c;并需要随时从Internet进行远程管理&#xff0c;考虑到易用性和灵活性&#xff0c;在Web服务器上启用OpenSSH服务&#xff0c;同时基于安全性考虑&#xff0c;需要对 SSH登录进行严格的控制&#xff0c;如图10…...

wpf ComboBox绑定数据及变更事件

定义ComboBox&#xff0c;以及SelectionChanged事件 <ComboBox x:Name"cmb_radius" Height"30" Width"65" FontSize"15" DisplayMemberPath"Value" SelectedValuePath"Key" HorizontalAlignment"Center&…...

SQL BETWEEN 操作符

BETWEEN 操作符选取介于两个值之间的数据范围内的值。这些值可以是数值、文本或者日期。 SQL BETWEEN 语法 SELECT column1, column2, ... FROM table_name WHERE column BETWEEN value1 AND value2; 参数说明&#xff1a; column1, column2, ...&#xff1a;要选择的字段名…...

Java位运算及移位运算

java中能表示整数数据类型的有byte、short、char、int、long&#xff0c;在计算机中占用的空间使用字节描述&#xff0c;1个字节使用8位二进制表示。 数据类型字节数二进制位数表示范围默认值byte18-27 – 27-10char2160 – 216-1\u0000 (代表字符为空 转成int就是0)short216-…...

上界通配符(? extends Type)

在Java中&#xff0c;? extends Type是一个上界通配符&#xff0c;表示参数化类型的上限是Type。这意味着容器可以持有Type类型的任何对象或者Type的子类型对象。 使用场景 这种类型的通配符常用于泛型方法中&#xff0c;允许方法接受Type的实例或其子类型的集合。这同样基于…...

zlib.decompressFile报错 【Bug已解决-鸿蒙开发】

文章目录 项目场景:问题描述原因分析:解决方案:方案1方案2此Bug解决方案总结寄语项目场景: 最近也是遇到了这个问题,看到网上也有人在询问这个问题,本文总结了自己和其他人的解决经验,解决了zlib.decompressFile报错 的问题。 问题: zlib.decompressFile报错,怎么解…...

54.网游逆向分析与插件开发-游戏增加自动化助手接口-项目需求与需求拆解

内容来源于&#xff1a;易道云信息技术研究院VIP课 项目需求&#xff1a; 为游戏增加VIP功能-自动化助手。自动化助手做的是首先要说一下背景&#xff0c;对于授权游戏来讲它往往年限都比较老&#xff0c;老游戏和新游戏设计理念是不同的&#xff0c;比如说老游戏基本上在10年…...

Spring Boot笔记2

3. SpringBoot原理分析 3.1. 起步依赖原理解析 3.1.1. 分析spring-boot-starter-parent 按住Ctrl键&#xff0c;然后点击pom.xml中的spring-boot-starter-parent&#xff0c;跳转到了spring-boot-starter-parent的pom.xml&#xff0c;xml配置如下&#xff08;只摘抄了部分重…...

MySQL5.7服务器 SQL 模式

官网地址&#xff1a;MySQL :: MySQL 5.7 Reference Manual :: 5.1.10 Server SQL Modes 欢迎关注留言&#xff0c;我是收集整理小能手&#xff0c;工具翻译&#xff0c;仅供参考&#xff0c;笔芯笔芯. MySQL 5.7 参考手册 / ... / 服务器 SQL 模式 5.1.10 服务器 SQL 模式…...

关于LayUI表格重载数据问题

目的 搜索框搜索内容重载数据只显示搜索到的结果 遇到的问题 在layui官方文档里介绍的table属性有data项,但使用下列代码 table.reload(test, {data:data //data为json数据}); 时发现&#xff0c;会会重新调用table.render的url拿到原来的数据&#xff0c;并不会显示出来传…...

MyBatis-mapper.xml配置

1、配置获取添加对象的ID <!-- 配置我们的添加方法&#xff0c;获取到新增加了一个monster对象的iduseGeneratedKeys"true" 意思是需要获取新加对象的主键值keyProperty"monster_id" 表示将获取到的id值赋值给Monster对象的monster_id属性 --><…...

【如何选择Mysql服务器的CPU核数及内存大小】

文章目录 &#x1f50a;博主介绍&#x1f964;本文内容&#x1f4e2;文章总结&#x1f4e5;博主目标 &#x1f50a;博主介绍 &#x1f31f;我是廖志伟&#xff0c;一名Java开发工程师、Java领域优质创作者、CSDN博客专家、51CTO专家博主、阿里云专家博主、清华大学出版社签约作…...

相机从app启动流程

一、流程框架图 二、具体流程分析 1、得到cameralist和对应的静态信息 目录如下: 重点代码分析: 启动相机前,先要通过getCameraIdList获取camera的个数以及id,然后可以通过getCameraCharacteristics获取对应id camera的capabilities(静态信息)进行一些openCamera前的…...

JS设计模式(4):观察者模式

JS设计模式(4):观察者模式 一、引入 在开发中&#xff0c;我们经常会遇到这样的场景&#xff1a;一个对象的状态变化需要自动通知其他对象&#xff0c;比如&#xff1a; 电商平台中&#xff0c;商品库存变化时需要通知所有订阅该商品的用户&#xff1b;新闻网站中&#xff0…...

【Go语言基础【13】】函数、闭包、方法

文章目录 零、概述一、函数基础1、函数基础概念2、参数传递机制3、返回值特性3.1. 多返回值3.2. 命名返回值3.3. 错误处理 二、函数类型与高阶函数1. 函数类型定义2. 高阶函数&#xff08;函数作为参数、返回值&#xff09; 三、匿名函数与闭包1. 匿名函数&#xff08;Lambda函…...

面向无人机海岸带生态系统监测的语义分割基准数据集

描述&#xff1a;海岸带生态系统的监测是维护生态平衡和可持续发展的重要任务。语义分割技术在遥感影像中的应用为海岸带生态系统的精准监测提供了有效手段。然而&#xff0c;目前该领域仍面临一个挑战&#xff0c;即缺乏公开的专门面向海岸带生态系统的语义分割基准数据集。受…...

4. TypeScript 类型推断与类型组合

一、类型推断 (一) 什么是类型推断 TypeScript 的类型推断会根据变量、函数返回值、对象和数组的赋值和使用方式&#xff0c;自动确定它们的类型。 这一特性减少了显式类型注解的需要&#xff0c;在保持类型安全的同时简化了代码。通过分析上下文和初始值&#xff0c;TypeSc…...

LangFlow技术架构分析

&#x1f527; LangFlow 的可视化技术栈 前端节点编辑器 底层框架&#xff1a;基于 &#xff08;一个现代化的 React 节点绘图库&#xff09; 功能&#xff1a; 拖拽式构建 LangGraph 状态机 实时连线定义节点依赖关系 可视化调试循环和分支逻辑 与 LangGraph 的深…...

Xela矩阵三轴触觉传感器的工作原理解析与应用场景

Xela矩阵三轴触觉传感器通过先进技术模拟人类触觉感知&#xff0c;帮助设备实现精确的力测量与位移监测。其核心功能基于磁性三维力测量与空间位移测量&#xff0c;能够捕捉多维触觉信息。该传感器的设计不仅提升了触觉感知的精度&#xff0c;还为机器人、医疗设备和制造业的智…...

阿里云Ubuntu 22.04 64位搭建Flask流程(亲测)

cd /home 进入home盘 安装虚拟环境&#xff1a; 1、安装virtualenv pip install virtualenv 2.创建新的虚拟环境&#xff1a; virtualenv myenv 3、激活虚拟环境&#xff08;激活环境可以在当前环境下安装包&#xff09; source myenv/bin/activate 此时&#xff0c;终端…...

用递归算法解锁「子集」问题 —— LeetCode 78题解析

文章目录 一、题目介绍二、递归思路详解&#xff1a;从决策树开始理解三、解法一&#xff1a;二叉决策树 DFS四、解法二&#xff1a;组合式回溯写法&#xff08;推荐&#xff09;五、解法对比 递归算法是编程中一种非常强大且常见的思想&#xff0c;它能够优雅地解决很多复杂的…...

CSS3相关知识点

CSS3相关知识点 CSS3私有前缀私有前缀私有前缀存在的意义常见浏览器的私有前缀 CSS3基本语法CSS3 新增长度单位CSS3 新增颜色设置方式CSS3 新增选择器CSS3 新增盒模型相关属性box-sizing 怪异盒模型resize调整盒子大小box-shadow 盒子阴影opacity 不透明度 CSS3 新增背景属性ba…...