在012的基础上,开启Druid的所有功能
012.SpringBoot+MyBatis+Postgre+Druid+Atomikos实现多库事物_℡メ㏑╭ァ小凯-CSDN博客
新引入一个AOP依赖
<dependency>
<groupId>aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.5.3</version>
</dependency>
创建一个Spring监控Bean
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 配置_Druid和Spring关联监控配置 -->
<bean id="druid-stat-interceptor" class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor"></bean>
<!-- 方法名正则匹配拦截配置 -->
<bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut"
scope="prototype">
<property name="patterns">
<list>
<value>com.javacore.mybatis.javacore.mapper.*</value>
<value>com.javacore.mybatis.postgres.mapper.*</value>
</list>
</property>
</bean>
<aop:config proxy-target-class="true">
<aop:advisor advice-ref="druid-stat-interceptor"
pointcut-ref="druid-stat-pointcut" />
</aop:config>
</beans>
主程序启动的时候开启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