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

資訊專欄INFORMATION COLUMN

SpringBoot集成Druid不支持多條SQL

leejan97 / 4554人閱讀

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

DataSource初始化Bean 添加

List proxyFilters = 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數據源配置
 * 
 * @author Joey
 * @Email 2434387555@qq.com
 *
 */
@Configuration
@EnableTransactionManagement // 啟注解事務管理
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優先于allow) : 如果滿足deny的話提示:Sorry, you are not
        // permitted to view this page.
        // 登錄查看信息的賬號密碼.
        servletRegistrationBean.addInitParameter("loginUsername", "joey");
        servletRegistrationBean.addInitParameter("loginPassword", "jay");
        // 是否能夠重置數據.
        servletRegistrationBean.addInitParameter("resetEnable", "false");
        return servletRegistrationBean;
    }

    /**
     * 注冊DruidFilter攔截
     * 
     * @return FilterRegistrationBean
     */
    @Bean
    public FilterRegistrationBean druidFilterRegistrationBean() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new WebStatFilter());
        Map initParams = new HashMap();
        // 設置忽略請求
        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;
    }
}
properties
#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

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

轉載請注明本文地址:http://m.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元查看
<