springboot复述,如何使用生菜配置多数据源

  介绍

这篇文章将为大家详细讲解有关springboot复述,如何使用生菜配置多数据源,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

springboot是什么

springboot一种全新的编程规范,其设计目的是用来简化新弹簧应用的初始搭建以及开发过程,springboot也是一个服务于框架的框架,服务范围是简化配置文件。

目前项目上需要连接两个复述,数据源,一个复述,数据源是单机模式,一个复述,数据源是分片集群模式,这里将具体配置列一下。

项目用的springboot版本为

& lt; parent>   ,,,,,,,& lt; groupId> org.springframework.boot   ,,,,,,,& lt; artifactId> spring-boot-starter-parent   ,,,,,,,& lt; version> 2.2.1.RELEASE   ,,,,,,,& lt; relativePath/祝辞,& lt; !——, lookup  parent 得到repository ——比;   ,,,& lt;/parent>

一、在yml中配置复述,数据源信息

复述:   ,,,集群:   ,,,,,节点:127.0.0.1:9001   ,,,生菜:   ,,,,,#连接池配置   ,,,,,池:   ,,,,,,,#连接池最大连接数   ,,,,,,,max-active: 20   ,,,,,,,#连接池最大等待时间,负数表示不做限制   ,,,,,,,最大等待:1   ,,,,,,,#最大空闲连接   ,,,,,,,最大空闲:9   ,,,,,,,#最小空闲连接   ,,,,,,,min-idle: 0   ,,,超时:500000   redis2才能:   ,,,主持人:127.0.0.1   ,,,端口:6385   ,,,生菜:   ,,,,,池:   ,,,,,,,max-active: 20   ,,,,,,,最大空闲:8   ,,,,,,,最大等待:1   ,,,,,,,min-idle: 0   ,,,超时:,500000

(这里的复述,都没有配置密码)

二、添加复述,配置类

package  com.cq.config;   ,   import  cn.hutool.core.convert.Convert;   import  org.apache.commons.pool2.impl.GenericObjectPoolConfig;   import  org.springframework.beans.factory.annotation.Autowired;   import  org.springframework.beans.factory.annotation.Qualifier;   import  org.springframework.beans.factory.annotation.Value;   import  org.springframework.boot.context.properties.ConfigurationProperties;   import  org.springframework.context.annotation.Bean;   import  org.springframework.context.annotation.Configuration;   import  org.springframework.context.annotation.Primary;   import  org.springframework.core.env.Environment;   import  org.springframework.core.env.MapPropertySource;   import  org.springframework.data.redis.connection.RedisClusterConfiguration;   import  org.springframework.data.redis.connection.RedisConnectionFactory;   import  org.springframework.data.redis.connection.RedisStandaloneConfiguration;   import  org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;   import  org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;   import  org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;   import  org.springframework.data.redis.core.RedisTemplate;   import  org.springframework.data.redis.serializer.RedisSerializer;   import  org.springframework.data.redis.serializer.StringRedisSerializer;   ,   import  java.io.Serializable;   import  java.util.HashMap;   import  java.util.Map;   ,/* *   ,* @author  cccccloud 提醒2020/11/16  17:16   ,*/@ configuration   public  class  RedisConfig  {   ,   ,,@ autowired   ,,,private  Environment 环境;   ,   ,,,@ value (“$ {spring.redis2.host}“)   ,,,private  String 主机;   ,,,@ value (“$ {spring.redis2.port}“)   ,,,private  String 港口;   ,,,@ value (“$ {spring.redis2.lettuce.pool.max-active}“)   ,,,private  String  max_active;   ,,,@ value (“$ {spring.redis2.lettuce.pool.max-idle}“)   ,,,private  String  max_idle;   ,,,@ value (“$ {spring.redis2.lettuce.pool.max-wait}“)   ,,,private  String  max_wait;   ,,,@ value (“$ {spring.redis2.lettuce.pool.min-idle}“)   ,,,private  String  min_idle;   ,   ,,,/* *   ,,,,*,配置生菜连接池   ,,,,   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

springboot复述,如何使用生菜配置多数据源