springboot使用druid连接池

2019-02-14  本文已影响0人  莫看烟雨

pom依赖

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.10</version>
        </dependency>

配置

# 不配置则不需要用户名密码
spring.datasource.druid.stat-view-servlet.login-username=admin
spring.datasource.druid.stat-view-servlet.login-password=123

web地址

public class DruidStatViewServletConfiguration {
    @Bean
    public ServletRegistrationBean statViewServletRegistrationBean(DruidStatProperties properties) {
        DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();
        ServletRegistrationBean registrationBean = new ServletRegistrationBean();
        registrationBean.setServlet(new StatViewServlet());
        registrationBean.addUrlMappings(config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*");

druid源码中把StatViewServlet的路径设置为/druid/*

故访问地址为: http://localhost:8080/druid

统计信息的原理

统计信息的生成是通过druid内部定义的filter实现,这些filter配置在这个文件:
/druid-1.1.10.jar!/META-INF/druid-filter.properties

官方文档

https://github.com/alibaba/druid/wiki/%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98

上一篇下一篇

猜你喜欢

热点阅读