您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
今天就跟大家聊聊有关SpringBoot中druid如何使用,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
配置application.yml文件
spring:
datasource:
username: root password: 123456 driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/test1?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true type: com.alibaba.druid.pool.DruidDataSource initialSize: 5 minIdle: 5 maxActive: 20 maxWait: 60000 timeBetweenEvictionRunsMillis: 60000 minEvictableIdleTimeMillis: 300000 validationQuery: SELECT 1 FROM DUAL testWhileIdle: true testOnBorrow: false testOnReturn: false poolPreparedStatements: true # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙 filters: stat,wall,log4j maxPoolPreparedStatementPerConnectionSize: 20 useGlobalDataSourceStat: true connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500 initialization-mode: always @Configuration
public class myDruid {
@ConfigurationProperties(prefix = "spring.datasource") [@Bean](https://my.oschina.net/bean) public DataSource dataSource(){ return new DruidDataSource(); } //配置Druid监控 [@Bean](https://my.oschina.net/bean) public ServletRegistrationBean statViewServlet(){ ServletRegistrationBean servletRegistrationBean= new ServletRegistrationBean(new StatViewServlet(),"/druid/*"); Map<String,Object> map =new HashMap<>(); map.put("loginUsername","admin"); map.put("loginPassword","admin"); servletRegistrationBean.setInitParameters(map); return servletRegistrationBean; } [@Bean](https://my.oschina.net/bean) public FilterRegistrationBean webStatFilter(){ FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); filterRegistrationBean.setFilter(new WebStatFilter()); Map<String,String> map = new HashMap<>(); map.put("exclusions","*.js,*.css,/druid/*"); filterRegistrationBean.setInitParameters(map); filterRegistrationBean.setUrlPatterns(Arrays.asList("/*")); return filterRegistrationBean; }
}
看完上述内容,你们对SpringBoot中druid如何使用有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。