Druid连接池配置

Druid连接池配置

Pom文件的引入

	 <dependency>
	    <groupId>com.alibaba</groupId>
	    <artifactId>druid</artifactId>
	    <version>1.0.18</version>
	 </dependency>

Filter配置

package com.thunisoft.zgsfzdzx.Config;

import com.alibaba.druid.support.http.WebStatFilter;

import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebInitParam;

@WebFilter(filterName="druidWebStatFilter",urlPatterns="/*",
        initParams={
                @WebInitParam(name="exclusions",value="*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*")
                //忽略资源
        })
public class DruidStatFilter extends WebStatFilter{
}

Application配置

package com.thunisoft.zgsfzdzx;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cache.annotation.EnableCaching;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableCaching
@SpringBootApplication
@ServletComponentScan //配置druid必须加的注解,如果不加,访问页面打不开,filter和servlet、listener之类的需要单独进行注册才能使用,spring boot里面提供了该注解起到注册作用
@MapperScan("com.thunisoft.zgsfzdzx.mybatis")
@EnableSwagger2//swagger注解,需要加一下,不加会不加载页面
public class ZgsfzdzxApplication {

    public static void main(String[] args) {
        SpringApplication.run(ZgsfzdzxApplication.class, args);

    }

}

application.yml配置

spring:
  thymeleaf:
    cache: false
  datasource:
    name: dataSource
    url: jdbc:ArteryBase://localhost:5432/db_sfzx
    username: xxxxx
    password: xxxxx
    driver-class-name: com.thunisoft.ArteryBase.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      #driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy
      max-active: 500
      min-idle: 100
      initial-size: 100
      filter:
        stat:
          enabled: true
      web-stat-filter:
        enabled: true
      stat-view-servlet:
        enabled: true
        url-pattern: /druid/*
        reset-enable: true
        login-username: druid
        login-password: druid
        #白名单,allow不填默认所有ip均可访问
        allow:
      validation-query: select version()
      test-while-idle: true	
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值