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

您的位置:首頁技術文章
文章詳情頁

springboot整合druid連接池的步驟

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

使用springboot默認的連接池

導入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默認的連接池

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

springboot整合druid連接池的步驟

使用連接池druid

導入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連接池的步驟

配置類中對druid屬性進行綁定

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

springboot整合druid連接池的步驟

配置Druid的監控后臺

//配置Druid的監控 //1、配置一個管理后臺的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','');//默認就是允許所有訪問 initParams.put('deny','192.168.15.21');//拒絕訪問 bean.setInitParameters(initParams); return bean; } //2、配置一個web監控的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監控失效需要導入log4j 依賴

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

以上就是springboot整合druid連接池的步驟的詳細內容,更多關于springboot整合druid連接池的資料請關注好吧啦網其它相關文章!

標簽: Spring
相關文章:
主站蜘蛛池模板: 阳新县| 建宁县| 诸城市| 沈阳市| 花垣县| 平谷区| 九龙县| 正安县| 新建县| 双峰县| 万安县| 仁布县| 石家庄市| 大悟县| 鲜城| 五台县| 昆山市| 呼玛县| 铜鼓县| 上思县| 色达县| 内乡县| 雅江县| 临洮县| 汉川市| 定州市| 澄城县| 弥勒县| 铁力市| 宁化县| 府谷县| 天柱县| 青神县| 宿州市| 寿光市| 新丰县| 桃园县| 当涂县| 依兰县| 桐梓县| 禄劝|