目录
Springboot整合druid
application.yml
# 此处用来配置数据库spring: datasource: url: jdbc:mysql://192.168.0.169:3306/jpa username: root password: xiaoyan type: com.alibaba.druid.pool.DruidDataSource driver-class-name: com.mysql.cj.jdbc.Driver # 下面为连接池的补充设置,应用到上面所有数据源中, 可以写, 可以不写 # 初始化大小,最小,最大 initialSize: 5 minIdle: 5 maxActive: 20 # 配置获取连接等待超时的时间 maxWait: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 timeBetweenEvictionRunsMillis: 60000 # 配置一个连接在池中最小生存的时间,单位是毫秒 minEvictableIdleTimeMillis: 300000 validationQuery: SELECT 1 FROM DUAL
DruidConfig
@Configurationpublic class DruidConfig { @ConfigurationProperties(prefix = "spring.datasource") @Bean public DataSource druid() { return new DruidDataSource(); } @Bean public ServletRegistrationBeanstatViewServlet() { ServletRegistrationBean registrationBean = new ServletRegistrationBean<>(); registrationBean.setServlet(new StatViewServlet()); registrationBean.setUrlMappings(Collections.singletonList("/druid/*")); //设置初始化参数 Map initMap = new HashMap<>(); // 登录账户密码 initMap.put("loginUsername", "admin"); initMap.put("loginPassword", "123456"); initMap.put("allow", ""); initMap.put("deny", ""); registrationBean.setInitParameters(initMap); return registrationBean; } @Bean public FilterRegistrationBean webStatFilter() { FilterRegistrationBean registrationBean = new FilterRegistrationBean<>(); registrationBean.setFilter(new WebStatFilter()); registrationBean.setUrlPatterns(Collections.singletonList("/*")); //设置初始化参数 Map initMap = new HashMap<>(1); initMap.put("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*"); registrationBean.setInitParameters(initMap); return registrationBean; }}
数据监控地址:http://localhost:8080/druid
posted on 2019-03-27 14:22 阅读( ...) 评论( ...)