记录下
首先目前大家经常做多数据原配置,但是需要将监控配置抽离出来,不能每个数据源都写一遍太麻烦了。
监控相关配置
package com.alibaba.druid.spring.boot.autoconfigure.properties;
@ConfigurationProperties("spring.datasource.druid")
public class DruidStatProperties {
private String[] aopPatterns;
private StatViewServlet statViewServlet = new StatViewServlet();
private WebStatFilter webStatFilter = new WebStatFilter();这里就很明显了,三个大配置项,具体的就不多说了,网上很多
aopPatterns spring监控相关 statViewServlet 权限相关配置 webStatFilter 监控页面相关配置
datasource: druid: # Spring监控AOP切入点,如x.y.z.service.*,配置多个英文逗号分隔 aop-patterns: com.test.service.* # WebStatFilter配置 web-stat-filter: enabled: true # 添加过滤规则 url-pattern: /* # 忽略过滤的格式 exclusions: '*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*' # StatViewServlet配置 stat-view-servlet: enabled: true # 访问路径为/druid时,跳转到StatViewServlet url-pattern: /druid/* # 是否能够重置数据 reset-enable: false # 需要账号密码才能访问控制台 login-username: druid login-password: druid123 # IP白名单 # allow: 127.0.0.1 # IP黑名单(共同存在时,deny优先于allow) # deny: 192.168.1.218
线面就是数据库相关的配置了
这个就更没啥可说的了。
注意的就是,自定义多数据源时,最后用现成的类,或者模拟原始类去加载对应的配置。
package com.alibaba.druid.pool;
*****
public abstract class DruidAbstractDataSource extends Wra***{
protected volatile boolean defaultAutoCommit = true;
protected volatile Boolean defaultReadOnly;
protected volatile Integer defaultTransactionIsolation;
protected volatile String defaultCatalog = null;
protected String name;
protected volatile String username;
protected volatile String password;
protected volatile String jdbcUrl;
protected volatile String driverClass;
protected volatile ClassLoader driverClassLoader;
protected volatile Properties connectProperties = new Properties();
protected volatile PasswordCallback passwordCallback;
protected volatile NameCallback userCallback;
protected volatile int initialSize = DEFAULT_INITIAL_SIZE;
protected volatile int maxActive = DEFAULT_MAX_ACTIVE_SIZE;
protected volatile int minIdle = DEFAULT_MIN_IDLE;
protected volatile int maxIdle = DEFAULT_MAX_IDLE;
protected volatile long maxWait = DEFAULT_MAX_WAIT;
protected int notFullTimeoutRetryCount = 0;
protected volatile String validationQuery = DEFAULT_VALIDATION_QUERY;
protected volatile int validationQueryTimeout = -1;
protected volatile boolean testOnBorrow = DEFAULT_TEST_ON_BORROW;
protected volatile boolean testOnReturn = DEFAULT_TEST_ON_RETURN;
********
}乐享:知识积累,快乐无限。