国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

springboot整合druid連接池的步驟

瀏覽:10日期:2023-04-05 18:53:49

使用springboot默認(rèn)的連接池

導(dǎo)入springboot data-jdbc依賴

<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jdbc</artifactId> </dependency>

配置文件配置連接池

spring: datasource: username: root password: 5201314 url: jdbc:mysql:///jqmb?serverTimezone=UTC driver-class-name: com.mysql.cj.jdbc.Driver

springboot默認(rèn)的連接池

@Autowired DataSource dataSource; @Test void contextLoads() { System.out.println(dataSource.getClass()); System.out.println('____________________________________'); }

springboot整合druid連接池的步驟

使用連接池druid

導(dǎo)入druid依賴

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

配置文件配置druid的屬性

spring: datasource: username: root password: 5201314 url: jdbc:mysql:///jqmb?serverTimezone=UTC driver-class-name: com.mysql.cj.jdbc.Driver 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: stat,wall,log4j maxPoolPreparedStatementPerConnectionSize: 20 useGlobalDataSourceStat: true connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500

springboot整合druid連接池的步驟

配置類中對(duì)druid屬性進(jìn)行綁定

@Configurationpublic class DataSource_Druid_Configure { @ConfigurationProperties(prefix = 'spring.datasource') @Bean public DruidDataSource getDataSour(){ return new DruidDataSource(); }

springboot整合druid連接池的步驟

配置Druid的監(jiān)控后臺(tái)

//配置Druid的監(jiān)控 //1、配置一個(gè)管理后臺(tái)的Servlet @Bean public ServletRegistrationBean statViewServlet(){ ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), '/druid/*'); Map<String,String> initParams = new HashMap<>(); initParams.put('loginUsername','admin');//登錄用戶名 initParams.put('loginPassword','123456');//登錄密碼 initParams.put('allow','');//默認(rèn)就是允許所有訪問 initParams.put('deny','192.168.15.21');//拒絕訪問 bean.setInitParameters(initParams); return bean; } //2、配置一個(gè)web監(jiān)控的filter @Bean public FilterRegistrationBean webStatFilter(){ FilterRegistrationBean bean = new FilterRegistrationBean(); bean.setFilter(new WebStatFilter()); Map<String,String> initParams = new HashMap<>(); initParams.put('exclusions','*.js,*.css,/druid/*'); bean.setInitParameters(initParams); bean.setUrlPatterns(Arrays.asList('/*')); return bean; }

訪問http://localhost:8090/druid/login.html

springboot整合druid連接池的步驟

如果sql監(jiān)控失效需要導(dǎo)入log4j 依賴

<dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency>

以上就是springboot整合druid連接池的步驟的詳細(xì)內(nèi)容,更多關(guān)于springboot整合druid連接池的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Spring
相關(guān)文章:
主站蜘蛛池模板: 泰兴市| 湟中县| 阳城县| 沽源县| 依安县| 元朗区| 海城市| 海口市| 永吉县| 二连浩特市| 军事| 平邑县| 衡南县| 砀山县| 东乡| 福贡县| 繁昌县| 新津县| 卫辉市| 江津市| 密云县| 宜阳县| 惠州市| 平南县| 拉孜县| 山阳县| 正安县| 德钦县| 咸丰县| 黑水县| 崇州市| 鸡东县| 昭苏县| 汉寿县| 界首市| 崇左市| 万源市| 久治县| 青铜峡市| 永修县| 漾濞|