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