A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© PureBlack 中级黑马   /  2018-1-22 17:25  /  2796 人查看  /  2 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

Druid已经在阿里巴巴部署了超过600个应用,经过一年多生产环境大规模部署的严苛考验。

applicationContext.xml 数据源配置

[XML] 纯文本查看 复制代码
<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
        xmlns:aop="http://www.springframework.org/schema/aop"  
        xmlns:tx="http://www.springframework.org/schema/tx"  
        xsi:schemaLocation="  
            [url]http://www.springframework.org/schema/beans[/url] [url]http://www.springframework.org/schema/beans/spring-beans-3.2.xsd[/url]  
            [url]http://www.springframework.org/schema/aop[/url] [url]http://www.springframework.org/schema/aop/spring-aop-3.2.xsd[/url]  
            [url]http://www.springframework.org/schema/tx[/url] [url]http://www.springframework.org/schema/tx/spring-tx-3.2.xsd[/url]">  
  
    <description>Spring公共配置文件 </description>  
  
    <!-- 定义受环境影响易变的变量 -->  
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
        <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />  
        <property name="ignoreResourceNotFound" value="true" />  
        <property name="locations">  
            <list>  
                <!-- 标准配置 -->  
                <value>classpath*:/application.properties</value>  
            </list>  
        </property>  
    </bean>  
      
        <!-- 数据源配置,使用应用内的c3p0数据库连接池 -->  
        <!--  
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">  
        <property name="driverClass" value="${jdbc.driverClassName}"/>  
        <property name="jdbcUrl" value="${jdbc.url}"/>  
        <property name="user" value="${jdbc.username}"/>  
        <property name="password" value="${jdbc.password}"/>  
        <property name="initialPoolSize" value="5"/>  
        <property name="minPoolSize" value="5"/>  
        <property name="maxPoolSize" value="100"/>  
        <property name="checkoutTimeout" value="5000"/>  
        <property name="maxIdleTime" value="1800"/>  
        <property name="idleConnectionTestPeriod" value="3000"/>  
        <property name="acquireIncrement" value="3"/>  
    </bean>  
    -->  
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">  
<property name="url" value="${jdbc.url}" />  
<property name="username" value="${jdbc.username}" />  
<property name="password" value="${jdbc.password}" />  
<property name="filters" value="stat" />  
<property name="maxActive" value="20" />   
<property name="initialSize" value="1" />  
<property name="maxWait" value="60000" />  
<property name="minIdle" value="1" />  
<property name="timeBetweenEvictionRunsMillis" value="3000" />  
<property name="minEvictableIdleTimeMillis" value="300000" />  
<property name="validationQuery" value="SELECT 'x'" />  
<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" />  
</bean>       
    <!-- Hibernate配置 -->  
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">  
        <property name="dataSource" ref="dataSource" />  
  
        <property name="hibernateProperties">  
            <props>  
                <prop key="hibernate.dialect">${jdbc.dialect}</prop>  
                <prop key="hibernate.show_sql">true</prop>  
                <prop key="hibernate.format_sql">true</prop>  
                <prop key="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory</prop>  
                <prop key="hibernate.cache.provider_configuration_file_resource_path">${hibernate.ehcache_config_file}</prop>  
                <prop key="hibernate.cache.use_query_cache">true</prop>  
                <prop key="hibernate.cache.use_second_level_cache">true</prop>  
            </props>  
        </property>  
        <property name="packagesToScan">  
            <list>  
                <value>com.kingmed.jusmartcare.health.entity</value>  
            </list>  
        </property>  
  
    </bean>  
      
    <!-- 事务管理器配置,单数据源事务 -->  
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">  
        <property name="sessionFactory" ref="sessionFactory" />  
    </bean>  
      
    <!-- 使用annotation定义事务 -->  
    <tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true" />     
  
</beans>  



web.xml 加上
[XML] 纯文本查看 复制代码
<servlet>       
  <servlet-name>DruidStatView</servlet-name>     
  <servlet-class>com.alibaba.druid.support.http.StatViewServlet</servlet-class>  
</servlet>   
<servlet-mapping>     
   <servlet-name>DruidStatView</servlet-name>  
   <url-pattern>/druid/*</url-pattern>  
 </servlet-mapping>


就可以了

2 个回复

倒序浏览
继续加油!每天总结,每天成长!
回复 使用道具 举报
温故而知新   加油哦   
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马