• Spring中数据源配置


    1.Spring单个连接的数据源为

    <bean id="simpleDataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
    <property name="url"
    value="jdbc:mysql://localhost:3306/hib?useUnicode=true&amp;characterEncoding=UTF-8"/>
    <property name="username" value="root"/>
    <property name="password" value="123456"/>
    </bean>

    2.连接池功能

    <bean id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close"
    >
      <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
      <property name="url"
    value="jdbc:mysql://localhost:3306/hib?useUnicode=true&amp;characterEncoding=UTF-8"/>
      <property name="username" value="root"/>
      <property name="password" value="123456"/>
      <property name="initialSize" value="1"/>
      <property name="maxActive" value="100"/>
      <property name="maxIdle" value="2"/>
      <property name="minIdle" value="1"/>
    </bean>

    注意连接串"jdbc:mysql://localhost:3306/hib?useUnicode=true&amp;characterEncoding=UTF-8"中的&符号的转义。destroy-method表示bean销毁时调用close方法。

    maxActive表示最多连接数,maxIdle表示最大空闲值,当经过一个高峰时间后,连接池会释放多余的连接,释放到一个怎样的数量,减少到maxIdle为止。minIdle表示连接池中至少有多少连接是可用的。

    需要导入数据源所依赖的jar文件,commons-dbcp.jar commons-pool.jar

    3.jndi数据源

    <bean id="jndiDataSource"
    class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/hib"/>
    </bean>

  • 相关阅读:
    Lintcode: Wood Cut
    Lintcode: Update Bits
    Lintcode: Route Between Two Nodes in Graph
    Lintcode: Flip Bits
    Leetcode: Maximum Size Subarray Sum Equals k
    Lintcode: Subarray Sum Closest
    Lintcode: Remove Node in Binary Search Tree
    Lintcode: Majority Number III
    Leetcode: Range Sum Query
    Leetcode: Create Maximum Number
  • 原文地址:https://www.cnblogs.com/tazi/p/2307497.html
Copyright © 2020-2023  润新知