013.SpringBoot多数据源+多库事物+Druid全监控

013.SpringBoot多数据源+多库事物+Druid全监控,第1张

013.SpringBoot多数据源+多库事物+Druid全监控 在012的基础上,开启Druid的所有功能

012.SpringBoot+MyBatis+Postgre+Druid+Atomikos实现多库事物_℡メ㏑╭ァ小凯-CSDN博客

 

新引入一个AOP依赖

    aspectj
    aspectjweaver
    1.5.3
创建一个Spring监控Bean



    
    

    
    
        
            
                com.javacore.mybatis.javacore.mapper.*
                com.javacore.mybatis.postgres.mapper.*
            
        
    

    
        
    

主程序启动的时候开启Spring监控
@importResource(locations = { "classpath:druid-bean.xml" })//看这里
public class CoreApplication {

    //项目启动时执行的方法
    public static void main(String[] args) {
        //...............
    }
}
对比012 Druid新增的其他监控配置
spring.datasource.druid.filters=stat,wall,config
#,wall,log4j,slf4j,config
# WebStatFilter配置
# 是否启用StatFilter默认值false
spring.datasource.druid.web-stat-filter.enabled=true
# 匹配的url
spring.datasource.druid.web-stat-filter.url-pattern=/*
# 排除一些不必要的url,比如.js,/jslib/等等
spring.datasource.druid.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*

全部Druid配置
server.port=8080
#单数据源
#spring.datasource.url=jdbc:postgresql://localhost:5432/javacore
#spring.datasource.username=postgres
#spring.datasource.password=asdf-1234
#spring.datasource.driver-class-name=org.postgresql.Driver

#多数据源
#spring.datasource.javacore.jdbc-url=jdbc:postgresql://localhost:5432/javacore
#spring.datasource.javacore.username=postgres
#spring.datasource.javacore.password=asdf-1234
#spring.datasource.javacore.driver-class-name=org.postgresql.Driver
#
#spring.datasource.postgres.jdbc-url=jdbc:postgresql://localhost:5432/postgres
#spring.datasource.postgres.username=postgres
#spring.datasource.postgres.password=asdf-1234
#spring.datasource.postgres.driver-class-name=org.postgresql.Driver

#mybatis.mapper-locations=classpath:mapper/*.xml


#连接池druid的配置信息+多数据源
spring.datasource.druid.javacore.url=jdbc:postgresql://localhost:5432/javacore
spring.datasource.druid.javacore.username=postgres
spring.datasource.druid.javacore.password=asdf-1234
spring.datasource.druid.javacore.driver-class-name=org.postgresql.Driver

spring.datasource.druid.postgres.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.druid.postgres.username=postgres
spring.datasource.druid.postgres.password=asdf-1234
spring.datasource.druid.postgres.driver-class-name=org.postgresql.Driver

spring.datasource.druid.initialSize=5
spring.datasource.druid.minIdle=5
spring.datasource.druid.maxActive=20
spring.datasource.druid.maxWait=60000
spring.datasource.druid.timeBetweenEvictionRunsMillis=60000
spring.datasource.druid.minEvictableIdleTimeMillis=300000
#spring.datasource.druid.validationQuery=SELECt 1 FROM DUAL
spring.datasource.druid.testWhileIdle=true
spring.datasource.druid.testonBorrow=false
spring.datasource.druid.testonReturn=false
spring.datasource.druid.poolPreparedStatements=true
spring.datasource.druid.maxPoolPreparedStatementPerConnectionSize=20
#SQL检测打开
#spring.datasource.druid.filter.stat.log-slow-sql=true
#spring.datasource.druid.filter.stat.enabled=true
#spring.datasource.druid.filter.merge-sql=true
#spring.datasource.druid.filter.stat.slow-sql-millis=2000

spring.datasource.druid.filters=stat,wall,config
#,wall,log4j,slf4j,config
# WebStatFilter配置
# 是否启用StatFilter默认值false
spring.datasource.druid.web-stat-filter.enabled=true
# 匹配的url
spring.datasource.druid.web-stat-filter.url-pattern=/*
# 排除一些不必要的url,比如.js,/jslib/等等
spring.datasource.druid.web-stat-filter.exclusions=*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*

# spring boot集成mybatis的方式打印sql
#mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
#spring.datasource.druid.filter.slf4j.enabled=true

#druid的监控站点
spring.datasource.druid.stat-view-servlet.enabled=true
spring.datasource.druid.stat-view-servlet.url-pattern=/druid/*
spring.datasource.druid.stat-view-servlet.reset-enable=true
spring.datasource.druid.stat-view-servlet.login-username=admin
spring.datasource.druid.stat-view-servlet.login-password=123

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5704884.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存