关于druid配置问题

今天在使用druid的时候,发现druid出现一系列故障。

废话不多说,直接上零配置的yml代码:

datasource:
  druid:
    db-type: com.alibaba.druid.pool.DruidDataSource
    driver-class-name: com.*.Driver
    url: jdbc:oscar://127.0.0.1:6379/*
    username: sc
    password: 2019
    initial-size: 10
    min-idle: 10
    max-active: 2000
    max-wait: 60000
    pool-prepared-statements: true
    max-pool-prepared-statement-per-connection-size: 20
    time-between-eviction-runs-millis: 60000
    min-evictable-idle-time-millis: 300000
    validation-query: SELECT 1 FROM DUAL
    validation-query-timeout: 60000
    test-while-idle: true
    test-on-borrow: false
    test-on-return: false
    connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
    web-stat-filter:
      enabled: true
      url-pattern: /*
      exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"
      session-stat-enable: true
      session-stat-max-count: 1000
      principal-session-name: null
      principal-cookie-name: null
      profile-enable: true
    stat-view-servlet:
      enabled: true
      deny: null
      url-pattern: /druid/*
      reset-enable: true
      allow: 127.0.0.1
      login-username: druid
      login-password: Love.TG
    filter:
      stat:
# 开启SQL监控
        enabled: true
        log-slow-sql: true
        slow-sql-millis: 2000
        merge-sql: true
      wall:
        config:
          multi-statement-allow: true
          drop-table-allow: false

发现SQL监控为空,是因为自己没有打开stat的enable;

Spring监控配置:(但是这样配置却无法程序启动了)

# Spring监控AOP切入点,如x.y.z.service.*,配置多个英文逗号分隔
aop-patterns: com.tty.service.*

 在配置过程中采用了博文(https://blog.csdn.net/jianggujin/article/details/80752709)的配置方式,但是报如下异常:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

网上搜索别人说如下配置:(但我觉得不好就没采用)

关于druid配置问题_第1张图片

druid包请选用

druid-spring-boot-starter

 后来选择了博文(https://blog.csdn.net/likaya20/article/details/79047064)的配置方式:

import com.alibaba.druid.support.spring.stat.DruidStatInterceptor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.aop.support.JdkRegexpMethodPointcut;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

/**
 * @author Love丶TG
 */
@Configuration
public class DruidConfiguration {

    @Bean
    public DruidStatInterceptor druidStatInterceptor() {
        return new DruidStatInterceptor();
    }

    @Bean
    @Scope("prototype")
    public JdkRegexpMethodPointcut druidStatPointcut() {
        JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();
        pointcut.setPattern("com.gkym.scpc.service.impl.*");
        return pointcut;
    }

    @Bean
    public DefaultPointcutAdvisor druidStatAdvisor(DruidStatInterceptor druidStatInterceptor, JdkRegexpMethodPointcut druidStatPointcut) {
        DefaultPointcutAdvisor defaultPointAdvisor = new DefaultPointcutAdvisor();
        defaultPointAdvisor.setPointcut(druidStatPointcut);
        defaultPointAdvisor.setAdvice(druidStatInterceptor);
        return defaultPointAdvisor;
    }
}

 本人亲自测试通过。(感谢博主!!!)

再后来发现shiro全拦截会拦截druid静态资源:

filterChainDefinitionMap.put("/static/**", "anon");
filterChainDefinitionMap.put("/swagger-ui.html","anon");
filterChainDefinitionMap.put("/swagger/**","anon");
filterChainDefinitionMap.put("/webjars/**", "anon");
filterChainDefinitionMap.put("/swagger-resources/**","anon");
filterChainDefinitionMap.put("/v2/**","anon");
filterChainDefinitionMap.put("/druid/**","anon");

 也感谢网友各位大佬,一路畅通。

你可能感兴趣的:(java,web)