SpringBootAdmin是码云上一个以springboot为核心的开源的后台管理系统。

这里是链接地址:点击打开链接

由于是后台系统,应该采用数据库分离,权限,用户,角色和业务模块分开。

application.properties

#服务端口
server.port = 8001
# ĿcontextPath
server.context-path = /
# session
server.session-timeout=60
#which active
#spring.profiles.active=pro  logging.level.com.mys.my.mapper = DEBUG#主数据库配置
spring.datasource.master.type = com.alibaba.druid.pool.DruidDataSource
spring.datasource.master.driver-class-name = com.mysql.jdbc.Driver
spring.datasource.master.name = geekcattle
spring.datasource.master.url=jdbc:mysql://localhost:3306/geekcattle?useUnicode=true&characterEncoding=UTF-8
spring.datasource.master.username = root
spring.datasource.master.password = 1234
spring.datasource.master.filters = stat
spring.datasource.master.maxActive = 20
spring.datasource.master.initialSize =  5
spring.datasource.master.maxWait = 60000
spring.datasource.master.minIdle = 20
spring.datasource.master.timeBetweenEvictionRunsMillis = 60000
spring.datasource.master.minEvictableIdleTimeMillis = 300000
spring.datasource.master.validationQuery = select 'x'
spring.datasource.master.testWhileIdle = true
spring.datasource.master.testOnBorrow = false
spring.datasource.master.testOnReturn = false
spring.datasource.master.poolPreparedStatements = true
spring.datasource.master.maxOpenPreparedStatements = 20#从数据库配置
spring.datasource.film.type = com.alibaba.druid.pool.DruidDataSource
spring.datasource.film.driver-class-name = com.mysql.jdbc.Driver
spring.datasource.film.name = film
spring.datasource.film.url=jdbc:mysql://localhost:3306/film?useUnicode=true&characterEncoding=UTF-8
spring.datasource.film.username = root
spring.datasource.film.password = 1234
spring.datasource.film.filters = stat
spring.datasource.film.maxActive = 20
spring.datasource.film.initialSize =  1
spring.datasource.film.maxWait = 60000
spring.datasource.film.minIdle = 20
spring.datasource.film.timeBetweenEvictionRunsMillis = 60000
spring.datasource.film.minEvictableIdleTimeMillis = 300000
spring.datasource.film.validationQuery = select 'x'
spring.datasource.film.testWhileIdle = true
spring.datasource.film.testOnBorrow = false
spring.datasource.film.testOnReturn = false
spring.datasource.film.poolPreparedStatements = true
spring.datasource.film.maxOpenPreparedStatements = 20#MVC
spring.mvc.view.prefix = classpath:/templates/
spring.mvc.view.suffix = .html
spring.mvc.date-format=yyyy-MM-dd HH:mm:ss
#
spring.thymeleaf.mode = HTML5
spring.thymeleaf.cache = false
spring.thymeleaf.encoding = UTF-8
spring.thymeleaf.content-type = text/html
#mybaties
spring.mapper.plugin = tk.mybatis.mapper.generator.MapperPlugin
spring.mapper.Mapper = com.mys.my.util.CustomerMapper
#json
spring.jackson.time-zone=Asia/Chongqing
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss
spring.jackson.joda-date-time-format=yyyy-MM-dd HH:mm:ss# Redis数据库索引(默认为0)
spring.redis.database=1
# Redis服务器地址
spring.redis.host=
# Redis服务器连接端口
spring.redis.port=6379
# Redis服务器连接密码(默认为空)
spring.redis.password=
# 连接池最大连接数(使用负值表示没有限制)
spring.redis.pool.max-active=30
# 超时时间
spring.redis.timeout=100000
# 连接池中的最大空闲连接
spring.redis.pool.max-idle=20
# 连接池最大阻塞等待时间(使用负值表示没有限制)
spring.redis.pool.max-wait=-1


MyBatisConfig.java

/** Copyright (c) 2017 <l_iupeiyu@qq.com> All rights reserved.*/package com.mys.my.conf;import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;import javax.sql.DataSource;import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
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.context.annotation.PropertySource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;import com.github.pagehelper.PageHelper;
/*** MyBatis基础配置*/
@Configuration
@PropertySource("classpath:application.properties")
//@EnableTransactionManagement
public class MyBatisConfig {//    @Autowired
//    DataSource dataSource;@Bean(name="masterDataSource")@ConfigurationProperties(prefix = "spring.datasource.master")@Primary//默认数据源public DataSource dataSource() {System.out.println("======================================"+DataSourceBuilder.create().build());return DataSourceBuilder.create().build();}@Bean(name="masterSqlSessionFactory")@Primary//默认数据源public SqlSessionFactory sqlSessionFactoryBean(@Qualifier("masterDataSource") DataSource dataSource) throws SQLException {SqlSessionFactoryBean bean = new SqlSessionFactoryBean();System.out.println("dataSource===================================================="+dataSource);bean.setDataSource(dataSource);bean.setTypeAliasesPackage("com.mys.my.model");//分页插件PageHelper pageHelper = new PageHelper();Properties properties = new Properties();properties.setProperty("reasonable", "true");properties.setProperty("supportMethodsArguments", "true");properties.setProperty("returnPageInfo", "check");properties.setProperty("params", "count=countSql");pageHelper.setProperties(properties);//添加插件bean.setPlugins(new Interceptor[]{pageHelper});//添加XML目录ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();try {bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));bean.setMapperLocations(resolver.getResources("classpath:mapper/*/*.xml"));return bean.getObject();} catch (Exception e) {e.printStackTrace();throw new RuntimeException(e);}}@Bean("masterSqlSessionTemplate")@Primarypublic SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory){return new SqlSessionTemplate(sqlSessionFactory);}@Bean("masterTransactionManager")@Primarypublic PlatformTransactionManager annotationDrivenTransactionManager(@Qualifier("masterDataSource") DataSource dataSource) {return new DataSourceTransactionManager(dataSource);}
}

新建一个数据库配置文件 MyBatisConfigFilm.java

/** Copyright (c) 2017 <l_iupeiyu@qq.com> All rights reserved.*/package com.mys.my.conf;import java.sql.SQLException;
import java.util.Properties;import javax.sql.DataSource;import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.SqlSessionTemplate;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;import com.github.pagehelper.PageHelper;
/*** MyBatis基础配置*/
@Configuration
@MapperScan(basePackages={"com.mys.my.mapper.fiz"},sqlSessionFactoryRef="filmSqlSessionFactory")
public class MyBatisConfigFilm{@Bean(name="filmDatasource")@ConfigurationProperties(prefix = "spring.datasource.film")public DataSource dataSource() {System.out.println("======================================"+DataSourceBuilder.create().build());return DataSourceBuilder.create().build();}@Bean(name="filmSqlSessionFactory")public SqlSessionFactory sqlSessionFactoryBean(@Qualifier("filmDatasource") DataSource dataSource) throws SQLException {SqlSessionFactoryBean bean = new SqlSessionFactoryBean();System.out.println("dataSource===================================================="+dataSource());bean.setDataSource(dataSource());bean.setTypeAliasesPackage("com.mys.my.pojo");//分页插件PageHelper pageHelper = new PageHelper();Properties properties = new Properties();properties.setProperty("reasonable", "true");properties.setProperty("supportMethodsArguments", "true");properties.setProperty("returnPageInfo", "check");properties.setProperty("params", "count=countSql");pageHelper.setProperties(properties);//添加插件bean.setPlugins(new Interceptor[]{pageHelper});//添加XML目录ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();try {
//        bean.setMapperLocations(resolver.getResources("classpath:mapper/*.xml"));bean.setMapperLocations(resolver.getResources("classpath:mapper/fiz/*.xml"));return bean.getObject();} catch (Exception e) {e.printStackTrace();throw new RuntimeException(e);}}@Bean("filmSqlSessionTemplate")public SqlSessionTemplate sqlSessionTemplate(@Qualifier("filmSqlSessionFactory")SqlSessionFactory sqlSessionFactory){return new SqlSessionTemplate(sqlSessionFactory);}@Bean(name = "filmTransactionManager")public PlatformTransactionManager annotationDrivenTransactionManager(@Qualifier("filmDatasource") DataSource dataSource) {return new DataSourceTransactionManager(dataSource());}
}

@MapperScan(basePackages={"com.mys.my.mapper.fiz"}的配置是扫描配置的dao文件 *.java
bean.setMapperLocations(resolver.getResources("classpath:mapper/fiz/*.xml"));
这个配置是扫描对应的mapper文件 *.xml。

MyBatisMapperScannerConfig.java

/** Copyright (c) 2017 <l_iupeiyu@qq.com> All rights reserved.*/package com.mys.my.conf;import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;//import com.mys.my.mapper.dataSource.MyFilmDatasource;import tk.mybatis.spring.mapper.MapperScannerConfigurer;import java.util.Properties;/*** MyBatis扫描接口,使用的tk.mybatis.spring.mapper.MapperScannerConfigurer,如果你不使用通用Mapper*/
@Configuration
//TODO 注意,由于MapperScannerConfigurer执行的比较早,所以必须有下面的注解
@AutoConfigureAfter(MyBatisConfig.class)
public class MyBatisMapperScannerConfig {@Beanpublic MapperScannerConfigurer mapperScannerConfigurer() {MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();mapperScannerConfigurer.setSqlSessionFactoryBeanName("masterSqlSessionFactory");mapperScannerConfigurer.setSqlSessionTemplateBeanName("masterSqlSessionTemplate");mapperScannerConfigurer.setBasePackage("com.mys.my.mapper");Properties properties = new Properties();properties.setProperty("mappers", "com.mys.my.util.CustomerMapper");properties.setProperty("notEmpty", "false");properties.setProperty("IDENTITY", "MYSQL");mapperScannerConfigurer.setProperties(properties);return mapperScannerConfigurer;}
}

关于码云开源项目SpringBootAdmin多数据源配置相关推荐

  1. idea新建springboot后端到前端_码云开源项目:利用SpringBoot+Vue 实现留言版

    一.新建Vue项目和SpringBoot项目 新建Vue项目 新建文件夹SpringBoot-Vue-MessageBoard创建Vue项目使用vue ui命令(需要vue 3.0选择刚才的目录 名字 ...

  2. 2016 年度码云热门项目排行榜 TOP 50

    原文地址:http://www.oschina.net/news/80909/2016-oschina-git-top-50?from=timeline&isappinstalled=0 阿里 ...

  3. 2017 年度码云新增项目排行榜 TOP 50,为它们打“call”

    2017 年度码云新增项目排行榜 TOP 50 正式出炉 !2017 结束了,我们来关注一下这一年里码云上新增的最热门的开源项目吧.此榜单根据 2017 年在码云上新增开源项目的 Watch.Star ...

  4. OpenStack、Docker、KVM被评为最火的云开源项目

    原文链接:http://www.searchsv.com.cn/showcontent_84583.htm 导读:最近调查显示OpenStack被认为是最流行的开源项目,Docker第二,KVM第三. ...

  5. 白嫖项目基于ssm房屋租赁系统源码【开源项目】

    ssm房屋租赁系统 运行工具:idea或eclipse均测试,可以运行. 开发技术: 后端ssm(spring springmvc mybatis)   前端:jsp  jquery 数据库:mysq ...

  6. Java 开源企业信息化建设平台 O2OA 入选码云 GVP 项目

    开发四年只会写业务代码,分布式高并发都不会还做程序员? >>>   经过兰德网络公司和O2OA团队全体成员的努力,O2OA获得码云最有价值开源项目称号. 2019年,我们将会更加努力 ...

  7. 码云上传代码添加标签_[Android] 发布码云(Gitee)项目到JitPack(最全完整流程)

    最近把github上的代码都转移到了码云上,而且github上的仓库可以很方便的迁移到码云,所以老代码的迁移问题不用考虑. 之前使用 JCenter 发布了一个 GitHub 开源项目,JCenter ...

  8. Git(码云-开源中国)入门小知识

    Git码云简介: 2013年开源中国上线大型开发云平台--"码云",将代码托管.质量检测.代码演示.团队协作等开发工具集成到云平台,免除繁杂的开发环境部署,节省成本,帮助软件开发者 ...

  9. 阿里云开源项目 OAM 负责人张磊入选「中国开源先锋 33 人」

    来源|阿里巴巴云原生公众号 2020 年 12 月 23 日,由 SegmentFault 思否发起的第二届"中国技术先锋"年度评选结果揭晓,CNCF 应用交付领域小组 Co-ch ...

最新文章

  1. js轮询导致服务器瘫痪_演进:Tengine 从 Web 代理服务器 到 分布式推送服务器
  2. BUUCTF-pwn2_sctf_2016(整数溢出+泄露libc)
  3. AC日记——字符替换 openjudge 1.7 08
  4. 使用autossh实现开机创建ssh tunnel的方法以及shell脚本.
  5. JavaScript使用技巧精萃 经典代码收藏版
  6. gis里创建要素面板怎么打开_【从零开始学GIS】ArcGIS中的绘图基本操作(二)
  7. java白色_java-将精灵颜色更改为白色
  8. python灰产_Python进行目录的对比
  9. 初识ProtoBuf(3.18.1)
  10. virtualbox增强功能-VBoxGuestAdditions安装
  11. python王者荣耀
  12. 转发-分享手机游戏辅助编程开发教程
  13. 山东理工大学ACM平台题答案关于C语言 1181 C语言实验——最小公倍数和最大公约数...
  14. python筛选excel符合条件的数据——python处理excel数据(四)
  15. 亚马逊服务器升降配和增/减磁盘
  16. Map的某种创建方式
  17. iPhone11与iPhonexs电池容量和充电速度对比
  18. 利用计算机教学的体会,利用多媒体教学设备心得体会
  19. 3.搭建K8s集群[无需ke学上网]
  20. 河北保定计算机学校大专分数线,河北多少分能上大专,河北大专院校最低分数线...

热门文章

  1. 工作399-openType=“getUserInfo“ lang=“zh_CN“ bindgetuserinfo=“getUserInfo“
  2. [html] 说说你对html中的置换元素和非置换元素的理解
  3. [css] 请说说CSS3实现文本效果的属性有哪些?
  4. 前端学习(1931)vue之电商管理系统电商系统之美化一层循环的UI结构删除业务逻辑实现分配权限的对话框实现
  5. spring学习(37):注入list类型
  6. 第三十七期:为什么2019年人工智能算法岗求职竞争如此激烈?
  7. 57javabean简介
  8. java学习(177):获取应用程序的路径
  9. 计算机操作系统(2):OS的发展过程
  10. input框在ios中的阴影问题