当前位置: 首页 > 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专家博主、阿里云专家博主、清华大学出版社签约作…...

【HarmonyOS 5.0】DevEco Testing:鸿蒙应用质量保障的终极武器

——全方位测试解决方案与代码实战 一、工具定位与核心能力 DevEco Testing是HarmonyOS官方推出的​​一体化测试平台​​&#xff0c;覆盖应用全生命周期测试需求&#xff0c;主要提供五大核心能力&#xff1a; ​​测试类型​​​​检测目标​​​​关键指标​​功能体验基…...

生成 Git SSH 证书

&#x1f511; 1. ​​生成 SSH 密钥对​​ 在终端&#xff08;Windows 使用 Git Bash&#xff0c;Mac/Linux 使用 Terminal&#xff09;执行命令&#xff1a; ssh-keygen -t rsa -b 4096 -C "your_emailexample.com" ​​参数说明​​&#xff1a; -t rsa&#x…...

苍穹外卖--缓存菜品

1.问题说明 用户端小程序展示的菜品数据都是通过查询数据库获得&#xff0c;如果用户端访问量比较大&#xff0c;数据库访问压力随之增大 2.实现思路 通过Redis来缓存菜品数据&#xff0c;减少数据库查询操作。 缓存逻辑分析&#xff1a; ①每个分类下的菜品保持一份缓存数据…...

今日学习:Spring线程池|并发修改异常|链路丢失|登录续期|VIP过期策略|数值类缓存

文章目录 优雅版线程池ThreadPoolTaskExecutor和ThreadPoolTaskExecutor的装饰器并发修改异常并发修改异常简介实现机制设计原因及意义 使用线程池造成的链路丢失问题线程池导致的链路丢失问题发生原因 常见解决方法更好的解决方法设计精妙之处 登录续期登录续期常见实现方式特…...

JVM虚拟机:内存结构、垃圾回收、性能优化

1、JVM虚拟机的简介 Java 虚拟机(Java Virtual Machine 简称:JVM)是运行所有 Java 程序的抽象计算机,是 Java 语言的运行环境,实现了 Java 程序的跨平台特性。JVM 屏蔽了与具体操作系统平台相关的信息,使得 Java 程序只需生成在 JVM 上运行的目标代码(字节码),就可以…...

【笔记】WSL 中 Rust 安装与测试完整记录

#工作记录 WSL 中 Rust 安装与测试完整记录 1. 运行环境 系统&#xff1a;Ubuntu 24.04 LTS (WSL2)架构&#xff1a;x86_64 (GNU/Linux)Rust 版本&#xff1a;rustc 1.87.0 (2025-05-09)Cargo 版本&#xff1a;cargo 1.87.0 (2025-05-06) 2. 安装 Rust 2.1 使用 Rust 官方安…...

Netty从入门到进阶(二)

二、Netty入门 1. 概述 1.1 Netty是什么 Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients. Netty是一个异步的、基于事件驱动的网络应用框架&#xff0c;用于…...

springboot 日志类切面,接口成功记录日志,失败不记录

springboot 日志类切面&#xff0c;接口成功记录日志&#xff0c;失败不记录 自定义一个注解方法 import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target;/***…...

认识CMake并使用CMake构建自己的第一个项目

1.CMake的作用和优势 跨平台支持&#xff1a;CMake支持多种操作系统和编译器&#xff0c;使用同一份构建配置可以在不同的环境中使用 简化配置&#xff1a;通过CMakeLists.txt文件&#xff0c;用户可以定义项目结构、依赖项、编译选项等&#xff0c;无需手动编写复杂的构建脚本…...

基于单片机的宠物屋智能系统设计与实现(论文+源码)

本设计基于单片机的宠物屋智能系统核心是实现对宠物生活环境及状态的智能管理。系统以单片机为中枢&#xff0c;连接红外测温传感器&#xff0c;可实时精准捕捉宠物体温变化&#xff0c;以便及时发现健康异常&#xff1b;水位检测传感器时刻监测饮用水余量&#xff0c;防止宠物…...