摘要:在初始化添加批量操作貼上自己的數(shù)據(jù)源配置啟注解事務(wù)管理注冊白名單黑名單存在共同時,優(yōu)先于如果滿足的話提示登錄查看信息的賬號密碼是否能夠重置數(shù)據(jù)注冊攔截設(shè)置忽略請求配置批量操作
在DataSource初始化Bean 添加
ListproxyFilters = new ArrayList (); WallFilter statFilter = new WallFilter(); WallConfig config = new WallConfig(); config.setMultiStatementAllow(true); // 批量操作 statFilter.setConfig(config); proxyFilters.add(statFilter); druidDataSource.setProxyFilters(proxyFilters);
貼上自己的Config
package com.wstro.config; import java.sql.SQLException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.sql.DataSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.ServletRegistrationBean; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; import org.springframework.transaction.annotation.EnableTransactionManagement; import com.alibaba.druid.filter.Filter; import com.alibaba.druid.pool.DruidDataSource; import com.alibaba.druid.support.http.StatViewServlet; import com.alibaba.druid.support.http.WebStatFilter; import com.alibaba.druid.wall.WallConfig; import com.alibaba.druid.wall.WallFilter; /** * Druid數(shù)據(jù)源配置 * * @author Joey * @Email [email protected] * */ @Configuration @EnableTransactionManagement // 啟注解事務(wù)管理 public class DataSourceConfig { private Logger logger = LoggerFactory.getLogger(DataSourceConfig.class); @Value("${spring.datasource.url}") private String dbUrl; @Value("${spring.datasource.username}") private String username; @Value("${spring.datasource.password}") private String password; @Value("${spring.datasource.driverClassName}") private String driverClassName; @Value("${spring.datasource.initialSize}") private int initialSize; @Value("${spring.datasource.minIdle}") private int minIdle; @Value("${spring.datasource.maxActive}") private int maxActive; @Value("${spring.datasource.maxWait}") private int maxWait; @Value("${spring.datasource.timeBetweenEvictionRunsMillis}") private int timeBetweenEvictionRunsMillis; @Value("${spring.datasource.minEvictableIdleTimeMillis}") private int minEvictableIdleTimeMillis; @Value("${spring.datasource.validationQuery}") private String validationQuery; @Value("${spring.datasource.testWhileIdle}") private boolean testWhileIdle; @Value("${spring.datasource.testOnBorrow}") private boolean testOnBorrow; @Value("${spring.datasource.testOnReturn}") private boolean testOnReturn; @Value("${spring.datasource.poolPreparedStatements}") private boolean poolPreparedStatements; @Value("${spring.datasource.maxPoolPreparedStatementPerConnectionSize}") private int maxPoolPreparedStatementPerConnectionSize; @Value("${spring.datasource.filters}") private String filters; @Value("${spring.datasource.connectionProperties}") private String connectionProperties; /** * 注冊DruidServlet * * @return ServletRegistrationBean */ @Bean public ServletRegistrationBean druidServletRegistrationBean() { ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(); servletRegistrationBean.setServlet(new StatViewServlet()); servletRegistrationBean.addUrlMappings("/druid/*"); // 白名單: servletRegistrationBean.addInitParameter("allow", "127.0.0.1"); // IP黑名單 (存在共同時,deny優(yōu)先于allow) : 如果滿足deny的話提示:Sorry, you are not // permitted to view this page. // 登錄查看信息的賬號密碼. servletRegistrationBean.addInitParameter("loginUsername", "joey"); servletRegistrationBean.addInitParameter("loginPassword", "jay"); // 是否能夠重置數(shù)據(jù). servletRegistrationBean.addInitParameter("resetEnable", "false"); return servletRegistrationBean; } /** * 注冊DruidFilter攔截 * * @return FilterRegistrationBean */ @Bean public FilterRegistrationBean druidFilterRegistrationBean() { FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(); filterRegistrationBean.setFilter(new WebStatFilter()); MapinitParams = new HashMap (); // 設(shè)置忽略請求 initParams.put("exclusions", "*.js,*.gif,*.jpg,*.bmp,*.png,*.css,*.ico,/druid/*"); filterRegistrationBean.setInitParameters(initParams); filterRegistrationBean.addUrlPatterns("/*"); return filterRegistrationBean; } /** * 配置DataSource * * @return DataSource * @throws SQLException */ @Bean(initMethod = "init", destroyMethod = "close") @Primary public DataSource dataSource() throws SQLException { DruidDataSource druidDataSource = new DruidDataSource(); druidDataSource.setUrl(dbUrl); druidDataSource.setUsername(username); druidDataSource.setPassword(password); druidDataSource.setDriverClassName(driverClassName); // configuration druidDataSource.setInitialSize(initialSize); druidDataSource.setMinIdle(minIdle); druidDataSource.setMaxActive(maxActive); druidDataSource.setMaxWait(maxWait); druidDataSource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis); druidDataSource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis); druidDataSource.setValidationQuery(validationQuery); druidDataSource.setTestWhileIdle(testWhileIdle); druidDataSource.setTestOnBorrow(testOnBorrow); druidDataSource.setTestOnReturn(testOnReturn); druidDataSource.setPoolPreparedStatements(poolPreparedStatements); druidDataSource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize); try { List proxyFilters = new ArrayList (); WallFilter statFilter = new WallFilter(); WallConfig config = new WallConfig(); config.setMultiStatementAllow(true); // 批量操作 statFilter.setConfig(config); proxyFilters.add(statFilter); druidDataSource.setProxyFilters(proxyFilters); druidDataSource.setFilters(filters); } catch (SQLException e) { logger.error("druid configuration initialization filter", e); } druidDataSource.setConnectionProperties(connectionProperties); return druidDataSource; } }
#JDBC # u6570u636Eu5E93u8BBFu95EEu914Du7F6E # u4E3Bu6570u636Eu6E90uFF0Cu9ED8u8BA4u7684 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource spring.datasource.driverClassName=com.mysql.jdbc.Driver spring.datasource.url=jdbc:mysql://192.168.1.88:3306/wstro?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8 spring.datasource.username=root spring.datasource.password=root # u4E0Bu9762u4E3Au8FDEu63A5u6C60u7684u8865u5145u8BBEu7F6EuFF0Cu5E94u7528u5230u4E0Au9762u6240u6709u6570u636Eu6E90u4E2D # u521Du59CBu5316u5927u5C0FuFF0Cu6700u5C0FuFF0Cu6700u5927 spring.datasource.initialSize=5 spring.datasource.minIdle=5 spring.datasource.maxActive=20 # u914Du7F6Eu83B7u53D6u8FDEu63A5u7B49u5F85u8D85u65F6u7684u65F6u95F4 spring.datasource.maxWait=60000 # u914Du7F6Eu95F4u9694u591Au4E45u624Du8FDBu884Cu4E00u6B21u68C0u6D4BuFF0Cu68C0u6D4Bu9700u8981u5173u95EDu7684u7A7Au95F2u8FDEu63A5uFF0Cu5355u4F4Du662Fu6BEBu79D2 spring.datasource.timeBetweenEvictionRunsMillis=60000 # u914Du7F6Eu4E00u4E2Au8FDEu63A5u5728u6C60u4E2Du6700u5C0Fu751Fu5B58u7684u65F6u95F4uFF0Cu5355u4F4Du662Fu6BEBu79D2 spring.datasource.minEvictableIdleTimeMillis=300000 spring.datasource.validationQuery=SELECT 1 FROM DUAL spring.datasource.testWhileIdle=true spring.datasource.testOnBorrow=false spring.datasource.testOnReturn=false # u6253u5F00PSCacheuFF0Cu5E76u4E14u6307u5B9Au6BCFu4E2Au8FDEu63A5u4E0APSCacheu7684u5927u5C0F spring.datasource.poolPreparedStatements=true spring.datasource.maxPoolPreparedStatementPerConnectionSize=20 # u914Du7F6Eu76D1u63A7u7EDFu8BA1u62E6u622Au7684filtersuFF0Cu53BBu6389u540Eu76D1u63A7u754Cu9762sqlu65E0u6CD5u7EDFu8BA1uFF0C"wall"u7528u4E8Eu9632u706Bu5899 spring.datasource.filters=stat,wall,log4j # u901Au8FC7connectPropertiesu5C5Eu6027u6765u6253u5F00mergeSqlu529Fu80FDuFF1Bu6162SQLu8BB0u5F55 spring.datasource.connectionProperties=druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000;druid.stat.logSlowSql=true; # u5408u5E76u591Au4E2ADruidDataSourceu7684u76D1u63A7u6570u636E #spring.datasource.useGlobalDataSourceStat=true
文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請注明本文地址:http://systransis.cn/yun/75478.html
摘要:配置想想,我們需要哪些數(shù)據(jù)庫要用到,數(shù)據(jù)庫連接池要用到橋接器要用到,因此要倉庫點我去倉庫中找到搜索這些加進去。 本文旨在用最通俗的語言講述最枯燥的基本知識 最近身邊的程序員掀起了學(xué)習(xí)springboot的熱潮,說什么學(xué)會了springboot在大街上就可以橫著走、什么有了springboot媽媽再也不擔(dān)心我的編程了、什么BAT都喜歡的框架...聽得作者那個心癢癢的,于是找了個時間,下載...
摘要:整合想著每次搭建新項目時框架都要從新搭建,基本常用的也就哪幾種,現(xiàn)在就來搭建一種常用的后臺框架,以后新開小項目可以直接拿來使用項目整體結(jié)構(gòu)圖新建空白項目,選中依賴略,也可以完全根據(jù)本人代碼操作文件依賴項展示 springboot整合tkMapper 想著每次搭建新項目時框架都要從新搭建,基本常用的也就哪幾種,現(xiàn)在就來搭建一種常用的springboot后臺框架,以后新開小項目可以直接拿來...
摘要:多數(shù)據(jù)源,一般用于對接多個業(yè)務(wù)上獨立的數(shù)據(jù)庫可能異構(gòu)數(shù)據(jù)庫。這也就導(dǎo)致異構(gòu)數(shù)據(jù)庫的檢查也是類似問題。內(nèi)容略數(shù)據(jù)源多數(shù)據(jù)源,涉及到異構(gòu)數(shù)據(jù)庫,必須明確指定,否則的轉(zhuǎn)換出錯取值內(nèi)容可參考初始連接數(shù)最大連接池數(shù)量。 開篇之前,說一句題外話。多數(shù)據(jù)源和動態(tài)數(shù)據(jù)源的區(qū)別。 多數(shù)據(jù)源,一般用于對接多個業(yè)務(wù)上獨立的數(shù)據(jù)庫(可能異構(gòu)數(shù)據(jù)庫)。 動態(tài)數(shù)據(jù)源,一般用于大型應(yīng)用對數(shù)據(jù)切分。 配置參考 如...
閱讀 2533·2021-11-15 11:38
閱讀 2893·2021-11-02 14:44
閱讀 3831·2021-09-26 10:13
閱讀 3073·2021-08-13 15:02
閱讀 790·2019-08-30 15:56
閱讀 1469·2019-08-30 15:53
閱讀 2367·2019-08-30 13:01
閱讀 3240·2019-08-29 12:57