国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

SpringBoot集成Druid不支持多條SQL

leejan97 / 4554人閱讀

摘要:在初始化添加批量操作貼上自己的數據源配置啟注解事務管理注冊白名單黑名單存在共同時,優先于如果滿足的話提示登錄查看信息的賬號密碼是否能夠重置數據注冊攔截設置忽略請求配置批量操作

DataSource初始化Bean 添加

</>復制代碼

  1. List proxyFilters = new ArrayList();
  2. WallFilter statFilter = new WallFilter();
  3. WallConfig config = new WallConfig();
  4. config.setMultiStatementAllow(true); // 批量操作
  5. statFilter.setConfig(config);
  6. proxyFilters.add(statFilter);
  7. druidDataSource.setProxyFilters(proxyFilters);

貼上自己的Config

</>復制代碼

  1. package com.wstro.config;
  2. import java.sql.SQLException;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import java.util.Map;
  7. import javax.sql.DataSource;
  8. import org.slf4j.Logger;
  9. import org.slf4j.LoggerFactory;
  10. import org.springframework.beans.factory.annotation.Value;
  11. import org.springframework.boot.web.servlet.FilterRegistrationBean;
  12. import org.springframework.boot.web.servlet.ServletRegistrationBean;
  13. import org.springframework.context.annotation.Bean;
  14. import org.springframework.context.annotation.Configuration;
  15. import org.springframework.context.annotation.Primary;
  16. import org.springframework.transaction.annotation.EnableTransactionManagement;
  17. import com.alibaba.druid.filter.Filter;
  18. import com.alibaba.druid.pool.DruidDataSource;
  19. import com.alibaba.druid.support.http.StatViewServlet;
  20. import com.alibaba.druid.support.http.WebStatFilter;
  21. import com.alibaba.druid.wall.WallConfig;
  22. import com.alibaba.druid.wall.WallFilter;
  23. /**
  24. * Druid數據源配置
  25. *
  26. * @author Joey
  27. * @Email 2434387555@qq.com
  28. *
  29. */
  30. @Configuration
  31. @EnableTransactionManagement // 啟注解事務管理
  32. public class DataSourceConfig {
  33. private Logger logger = LoggerFactory.getLogger(DataSourceConfig.class);
  34. @Value("${spring.datasource.url}")
  35. private String dbUrl;
  36. @Value("${spring.datasource.username}")
  37. private String username;
  38. @Value("${spring.datasource.password}")
  39. private String password;
  40. @Value("${spring.datasource.driverClassName}")
  41. private String driverClassName;
  42. @Value("${spring.datasource.initialSize}")
  43. private int initialSize;
  44. @Value("${spring.datasource.minIdle}")
  45. private int minIdle;
  46. @Value("${spring.datasource.maxActive}")
  47. private int maxActive;
  48. @Value("${spring.datasource.maxWait}")
  49. private int maxWait;
  50. @Value("${spring.datasource.timeBetweenEvictionRunsMillis}")
  51. private int timeBetweenEvictionRunsMillis;
  52. @Value("${spring.datasource.minEvictableIdleTimeMillis}")
  53. private int minEvictableIdleTimeMillis;
  54. @Value("${spring.datasource.validationQuery}")
  55. private String validationQuery;
  56. @Value("${spring.datasource.testWhileIdle}")
  57. private boolean testWhileIdle;
  58. @Value("${spring.datasource.testOnBorrow}")
  59. private boolean testOnBorrow;
  60. @Value("${spring.datasource.testOnReturn}")
  61. private boolean testOnReturn;
  62. @Value("${spring.datasource.poolPreparedStatements}")
  63. private boolean poolPreparedStatements;
  64. @Value("${spring.datasource.maxPoolPreparedStatementPerConnectionSize}")
  65. private int maxPoolPreparedStatementPerConnectionSize;
  66. @Value("${spring.datasource.filters}")
  67. private String filters;
  68. @Value("${spring.datasource.connectionProperties}")
  69. private String connectionProperties;
  70. /**
  71. * 注冊DruidServlet
  72. *
  73. * @return ServletRegistrationBean
  74. */
  75. @Bean
  76. public ServletRegistrationBean druidServletRegistrationBean() {
  77. ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean();
  78. servletRegistrationBean.setServlet(new StatViewServlet());
  79. servletRegistrationBean.addUrlMappings("/druid/*");
  80. // 白名單:
  81. servletRegistrationBean.addInitParameter("allow", "127.0.0.1");
  82. // IP黑名單 (存在共同時,deny優先于allow) : 如果滿足deny的話提示:Sorry, you are not
  83. // permitted to view this page.
  84. // 登錄查看信息的賬號密碼.
  85. servletRegistrationBean.addInitParameter("loginUsername", "joey");
  86. servletRegistrationBean.addInitParameter("loginPassword", "jay");
  87. // 是否能夠重置數據.
  88. servletRegistrationBean.addInitParameter("resetEnable", "false");
  89. return servletRegistrationBean;
  90. }
  91. /**
  92. * 注冊DruidFilter攔截
  93. *
  94. * @return FilterRegistrationBean
  95. */
  96. @Bean
  97. public FilterRegistrationBean druidFilterRegistrationBean() {
  98. FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
  99. filterRegistrationBean.setFilter(new WebStatFilter());
  100. Map initParams = new HashMap();
  101. // 設置忽略請求
  102. initParams.put("exclusions", "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*");
  103. filterRegistrationBean.setInitParameters(initParams);
  104. filterRegistrationBean.addUrlPatterns("/*");
  105. return filterRegistrationBean;
  106. }
  107. /**
  108. * 配置DataSource
  109. *
  110. * @return DataSource
  111. * @throws SQLException
  112. */
  113. @Bean(initMethod = "init", destroyMethod = "close")
  114. @Primary
  115. public DataSource dataSource() throws SQLException {
  116. DruidDataSource druidDataSource = new DruidDataSource();
  117. druidDataSource.setUrl(dbUrl);
  118. druidDataSource.setUsername(username);
  119. druidDataSource.setPassword(password);
  120. druidDataSource.setDriverClassName(driverClassName);
  121. // configuration
  122. druidDataSource.setInitialSize(initialSize);
  123. druidDataSource.setMinIdle(minIdle);
  124. druidDataSource.setMaxActive(maxActive);
  125. druidDataSource.setMaxWait(maxWait);
  126. druidDataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
  127. druidDataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
  128. druidDataSource.setValidationQuery(validationQuery);
  129. druidDataSource.setTestWhileIdle(testWhileIdle);
  130. druidDataSource.setTestOnBorrow(testOnBorrow);
  131. druidDataSource.setTestOnReturn(testOnReturn);
  132. druidDataSource.setPoolPreparedStatements(poolPreparedStatements);
  133. druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
  134. try {
  135. List proxyFilters = new ArrayList();
  136. WallFilter statFilter = new WallFilter();
  137. WallConfig config = new WallConfig();
  138. config.setMultiStatementAllow(true); // 批量操作
  139. statFilter.setConfig(config);
  140. proxyFilters.add(statFilter);
  141. druidDataSource.setProxyFilters(proxyFilters);
  142. druidDataSource.setFilters(filters);
  143. } catch (SQLException e) {
  144. logger.error("druid configuration initialization filter", e);
  145. }
  146. druidDataSource.setConnectionProperties(connectionProperties);
  147. return druidDataSource;
  148. }
  149. }
properties

</>復制代碼

  1. #JDBC
  2. # u6570u636Eu5E93u8BBFu95EEu914Du7F6E
  3. # u4E3Bu6570u636Eu6E90uFF0Cu9ED8u8BA4u7684
  4. spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
  5. spring.datasource.driverClassName=com.mysql.jdbc.Driver
  6. spring.datasource.url=jdbc:mysql://192.168.1.88:3306/wstro?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8
  7. spring.datasource.username=root
  8. spring.datasource.password=root
  9. # u4E0Bu9762u4E3Au8FDEu63A5u6C60u7684u8865u5145u8BBEu7F6EuFF0Cu5E94u7528u5230u4E0Au9762u6240u6709u6570u636Eu6E90u4E2D
  10. # u521Du59CBu5316u5927u5C0FuFF0Cu6700u5C0FuFF0Cu6700u5927
  11. spring.datasource.initialSize=5
  12. spring.datasource.minIdle=5
  13. spring.datasource.maxActive=20
  14. # u914Du7F6Eu83B7u53D6u8FDEu63A5u7B49u5F85u8D85u65F6u7684u65F6u95F4
  15. spring.datasource.maxWait=60000
  16. # u914Du7F6Eu95F4u9694u591Au4E45u624Du8FDBu884Cu4E00u6B21u68C0u6D4BuFF0Cu68C0u6D4Bu9700u8981u5173u95EDu7684u7A7Au95F2u8FDEu63A5uFF0Cu5355u4F4Du662Fu6BEBu79D2
  17. spring.datasource.timeBetweenEvictionRunsMillis=60000
  18. # u914Du7F6Eu4E00u4E2Au8FDEu63A5u5728u6C60u4E2Du6700u5C0Fu751Fu5B58u7684u65F6u95F4uFF0Cu5355u4F4Du662Fu6BEBu79D2
  19. spring.datasource.minEvictableIdleTimeMillis=300000
  20. spring.datasource.validationQuery=SELECT 1 FROM DUAL
  21. spring.datasource.testWhileIdle=true
  22. spring.datasource.testOnBorrow=false
  23. spring.datasource.testOnReturn=false
  24. # u6253u5F00PSCacheuFF0Cu5E76u4E14u6307u5B9Au6BCFu4E2Au8FDEu63A5u4E0APSCacheu7684u5927u5C0F
  25. spring.datasource.poolPreparedStatements=true
  26. spring.datasource.maxPoolPreparedStatementPerConnectionSize=20
  27. # u914Du7F6Eu76D1u63A7u7EDFu8BA1u62E6u622Au7684filtersuFF0Cu53BBu6389u540Eu76D1u63A7u754Cu9762sqlu65E0u6CD5u7EDFu8BA1uFF0C"wall"u7528u4E8Eu9632u706Bu5899
  28. spring.datasource.filters=stat,wall,log4j
  29. # u901Au8FC7connectPropertiesu5C5Eu6027u6765u6253u5F00mergeSqlu529Fu80FDuFF1Bu6162SQLu8BB0u5F55
  30. spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000;druid.stat.logSlowSql=true;
  31. # u5408u5E76u591Au4E2ADruidDataSourceu7684u76D1u63A7u6570u636E
  32. #spring.datasource.useGlobalDataSourceStat=true

文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。

轉載請注明本文地址:http://specialneedsforspecialkids.com/yun/75478.html

相關文章

  • 單手擼了個springboot+mybatis+druid

    摘要:配置想想,我們需要哪些數據庫要用到,數據庫連接池要用到橋接器要用到,因此要倉庫點我去倉庫中找到搜索這些加進去。 本文旨在用最通俗的語言講述最枯燥的基本知識 最近身邊的程序員掀起了學習springboot的熱潮,說什么學會了springboot在大街上就可以橫著走、什么有了springboot媽媽再也不擔心我的編程了、什么BAT都喜歡的框架...聽得作者那個心癢癢的,于是找了個時間,下載...

    adie 評論0 收藏0
  • springboot (一)集成tkmapper

    摘要:整合想著每次搭建新項目時框架都要從新搭建,基本常用的也就哪幾種,現在就來搭建一種常用的后臺框架,以后新開小項目可以直接拿來使用項目整體結構圖新建空白項目,選中依賴略,也可以完全根據本人代碼操作文件依賴項展示 springboot整合tkMapper 想著每次搭建新項目時框架都要從新搭建,基本常用的也就哪幾種,現在就來搭建一種常用的springboot后臺框架,以后新開小項目可以直接拿來...

    Shihira 評論0 收藏0
  • SpringBoot+Mybatis配置Druid多數據源

    摘要:多數據源,一般用于對接多個業務上獨立的數據庫可能異構數據庫。這也就導致異構數據庫的檢查也是類似問題。內容略數據源多數據源,涉及到異構數據庫,必須明確指定,否則的轉換出錯取值內容可參考初始連接數最大連接池數量。 開篇之前,說一句題外話。多數據源和動態數據源的區別。 多數據源,一般用于對接多個業務上獨立的數據庫(可能異構數據庫)。 動態數據源,一般用于大型應用對數據切分。 配置參考 如...

    Songlcy 評論0 收藏0

發表評論

0條評論

最新活動
閱讀需要支付1元查看
<