久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

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

springboot整合druid連接池的步驟

瀏覽:40日期: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
相關文章:
主站蜘蛛池模板: 宝丰县| 大邑县| 蓬安县| 高雄县| 遂平县| 临颍县| 盐山县| 息烽县| 两当县| 和静县| 曲阜市| 睢宁县| 花垣县| 麟游县| 永清县| 肥东县| 安徽省| 新邵县| 南京市| 施甸县| 监利县| 和平区| 泾川县| 高邑县| 徐州市| 南康市| 博野县| 泊头市| 乌拉特前旗| 大同县| 彭山县| 青川县| 万山特区| 陵川县| 吴忠市| 潜江市| 大连市| 新巴尔虎左旗| 荃湾区| 云南省| 都匀市|