druid 데이터베이스 연결 탱크 설정

11488 단어 데이터 뱅 크
대부분의 내용 은 알 리 바 바 / druid 에서 발췌 되 었 습 니 다.
1. jar 패키지 도입
<dependency>
    <groupId>com.alibabagroupId>
    <artifactId>druidartifactId>
    <version>${druid-version}version>
dependency>

2. spring 프로필 에 dataSource 설정

<bean id="druidDataSource_wxsr" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
    
    <property name="url" value="${druid.wxsr.url}" />
    <property name="username" value="${druid.wxsr.username}" />
    <property name="password" value="${druid.wxsr.password}" />

    
    <property name="initialSize" value="1" />
    <property name="minIdle" value="1" />
    <property name="maxActive" value="20" />

    
    <property name="maxWait" value="60000" />

    
    <property name="timeBetweenEvictionRunsMillis" value="60000" />

    
    <property name="minEvictableIdleTimeMillis" value="300000" />

    <property name="validationQuery" value="SELECT 'x' FROM DUAL" />
    <property name="testWhileIdle" value="true" />
    <property name="testOnBorrow" value="false" />
    <property name="testOnReturn" value="false" />

    
    <property name="poolPreparedStatements" value="true" />
    <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />

    
    <property name="filters" value="stat,log4j" />
bean>

3. WebStatFilter 설정
<filter>
    <filter-name>DruidWebStatFilterfilter-name>
    <filter-class>com.alibaba.druid.support.http.WebStatFilterfilter-class>
    <init-param>
        <param-name>exclusionsparam-name>
        <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*param-value>
    init-param>
    <init-param>
        <param-name>profileEnableparam-name>
        <param-value>trueparam-value>
    init-param>
filter>
<filter-mapping>
    <filter-name>DruidWebStatFilterfilter-name>
    <url-pattern>/*url-pattern>
filter-mapping>

4. Druid 의 통계 정 보 를 보 여 주 는 설정

<servlet>
    <servlet-name>DruidStatViewservlet-name>
    <servlet-class>com.alibaba.druid.support.http.StatViewServletservlet-class>
    <init-param>
        
        <param-name>resetEnableparam-name>
        <param-value>trueparam-value>
    init-param>
    <init-param>
        
        <param-name>loginUsernameparam-name>
        <param-value>druidparam-value>
    init-param>
    <init-param>
        
        <param-name>loginPasswordparam-name>
        <param-value>druid123param-value>
    init-param>
servlet>
<servlet-mapping>
    <servlet-name>DruidStatViewservlet-name>
    <url-pattern>/druid/*url-pattern>
servlet-mapping>

5. 통계 페이지 방문
http://127.0.0.1:8080/xxxx/druid/index.html

좋은 웹페이지 즐겨찾기