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

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;}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/413072.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

java将字符串转换成可执行代码

使用commons的jexl可实现将字符串变成可执行代码的功能通用工具类&#xff1a;/** * * author: Longjun * Description: 使用commons的jexl可实现将字符串变成可执行代码的功能 * date:2016年3月21日 下午1:45:13 */ public static Object convertToCode(String jexlExp,Map&…

22.敏捷估计与规划——Why Agile Planning Works笔记

00.经常进行重规划&#xff0c;是敏捷规划和估计为有效探索新产品开发解决方案控件提供支持的方法之一。在每次迭代开始时&#xff0c;都要建立该迭代的计划。发布计划要么在每次迭代后背更新&#xff0c;或者最差的时候也要在每几次迭代后被更新。计划要保持有用&#xff0c;就…

[css] 当全国哀悼日时,怎么让整个网站变成灰色呢?

[css] 当全国哀悼日时&#xff0c;怎么让整个网站变成灰色呢&#xff1f; body{-webkit-filter: grayscale(1);filter: grayscale(1); }/* OR */body{-webkit-filter: grayscale(100%);filter: grayscale(100%); }个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识…

jeesite使用心得(一)

<update id"updateSelective">UPDATE ${table.name} <set> <#list table.columnList as c><#if c.isEdit?? && c.isEdit "1"><if test"${c.javaFieldId} ! null" >${c.name} ${"#"}{${c.ja…

java List集合转换为List Map集合

/*** 将List<Object>转换为List<Map<String,Object>>* param list* return*/private List<Map<String,Object>> convertListMap(List<Object> list){List<Map<String,Object>> mapsnew ArrayList<Map<String,Object>…

[css] 如果给一个元素设置background-color,它的颜色会填充哪些区域呢?

[css] 如果给一个元素设置background-color,它的颜色会填充哪些区域呢&#xff1f; 个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大家一起讨论 主目录 与歌谣一起通关前端面试题

jeesite使用心得(二)

按照上一篇的内容&#xff0c;有一些缺陷的地方。分页对象传什么都可以&#xff0c;但是返回的是list<HashMap<String,Object>>集合的话&#xff0c;分页方法就是无效了。这里把我写的贴一下: Controller: // 带条件分页Integer pageNo null;Integer pageSize …

jqgrid删除某一列(隐藏)

$("#jqGrid_table").setGridParam().hideCol("列的名字");//隐藏 $("#jqGrid_table").setGridParam().showCol("列的名字");//显示

一个设计项调另一个设计项(支持多选传值)

//方案管理中起企业按钮中的前端代码function(button, record, e) {debugger; // 中断调试指令&#xff0c;可以手动删除它var me this; // this 为列表视图控制器var viewModel this.getViewModel(); // 获取视图模型var grid this.getView();…

[css] 使用css3做一个魔方旋转的效果

[css] 使用css3做一个魔方旋转的效果 总的来说&#xff0c;用了一些 3D 效果的样式&#xff0c;如 translate3d&#xff0c;rotate3d&#xff0c;perspective&#xff0c;transform-style: preserve-3d; 等&#xff0c;感兴趣的可以去看看它的样式文件个人简介 我是歌谣&…

linux安装elasticsearch5.5

大家好&#xff0c;我是烤鸭: 我是采用官网下载tar包的方式安装的。 安装环境&#xff1a;centos 7.2,jdk1.8 下载地址: https://www.elastic.co/downloads/elasticsearch 1.解压缩&#xff1a; 解压 elasticsearch.5.5.2.tar.gz tar -zxvf elasticsearch-5.2.2.tar.gz2.创…

eclipse创建folder变成package解决方案

1,项目右键—-选择properties 2,选择Java Build Path—-选择Source 3,选择xxxx/src/main/resources下面的Excluded,点击Edit 4,在Exclusion patterns下面选中第一个&#xff0c;点击右边的edit 5,方案一&#xff1a;在Browse按钮左边的输入框修改为 ** 方案二&#xff1a;…

[css] 手写一个使用css3旋转硬币的效果

[css] 手写一个使用css3旋转硬币的效果 两种实现方式&#xff1a;1、animationkeyframes 2、transition&#xff1a; //第一种实现方式 <style type"text/css"> .around{ width:200px; height:200px; background:orange; /*圆形的话看不出效果&#xff0c;所以…

0076-小升初1:生日蛋糕

题目 小升初1&#xff1a;生日蛋糕难度级别&#xff1a;B&#xff1b; 运行时间限制&#xff1a;1000ms&#xff1b; 运行空间限制&#xff1a;256000KB&#xff1b; 代码长度限制&#xff1a;2000000B 试题描述一个中学生&#xff08;在线测评系统的系统管理员&#xff09;过生…

tomcat9-jenkins:insufficient free space available after evicting expired cache entries-consider

解决该问题方法&#xff0c;修改tomcat/conf/context.xml文件&#xff0c;增加资源最大可缓存的大小&#xff1a;<Context><!-- Default set of monitored resources. If one of these changes, the --><!-- web application will be reloaded. …

[css] height和line-height的区别是什么呢?

[css] height和line-height的区别是什么呢&#xff1f; height&#xff1a;元素content area的高度line-height&#xff1a;元素中&#xff0c;多行文字基线的距离个人简介 我是歌谣&#xff0c;欢迎和大家一起交流前后端知识。放弃很容易&#xff0c; 但坚持一定很酷。欢迎大…

laydate根据开始时间或者结束时间限制范围

$(window).load(function(){//初始化时间控件var cartimeDate laydate.render({elem: #cartime //用车时间,type: datetime,format: yyyy-MM-dd HH:mm,done:function(value, date){returntimeDate.config.mingetDateArray(date);//重点}});var returntimeDate laydate.render…

Django Form -- 字段的用法扩展

form.py的代码 from django import forms from django.forms import fields from django.forms import widgetsclass DetailForm(forms.Form):inp fields.CharField()required inp fields.CharField(requiredFalse)  #表单可以为空 inp fields.CharField(requiredTrue) …

linux部署jenkins,tomcat9

大家好&#xff0c;我是烤鸭&#xff1a;今天分享的是 linux部署jenkins,tomcat9 安装环境&#xff1a;linux centos7.2tomcat 9.1Jenkins 2.73JDK 1.8maven 3.5git 2.91. 下载jenkins&#xff1a;https://jenkins.io/download/ 我选择的war下载。2. 安装…

[css] 请用css写一个扫码的加载动画图

[css] 请用css写一个扫码的加载动画图 Keyframes donut-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } } .donut { display: inline-block; border: 4px solid rgba(0, 0, 0, 0.1); border-left-color: #7983ff; border-radius: 50%; width: 3…