• 连接数据源的几种方式


    <!-- 注册数据源:Spring内置连接池 -->
    <!-- <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
      <property name="url" value="jdbc:mysql://127.0.0.1:3306/test"/>
      <property name="username" value="root"/>
      <property name="password" value="123456"/>
    </bean> -->
    <!-- <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
      <property name="driverClassName" value="${jdbc.driver}"/>
      <property name="url" value="${jdbc.url}"/>
      <property name="username" value="${jdbc.user}"/>
      <property name="password" value="${jdbc.password}"/>
    </bean> -->

    <!-- 注册数据源:DBCP-->
    <!--
    <bean id="myDataSource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
      <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
      <property name="url" value="jdbc:mysql://127.0.0.1:3306/test"/>
      <property name="username" value="root"/>
      <property name="password" value="123456"/>
    </bean> -->

    <!-- 注册数据源:C3P0-->
    <!-- <bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> -->
      <bean id="myDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver"/>
        <property name="jdbcUrl" value="jdbc:mysql://127.0.0.1:3306/test"/>
        <property name="user" value="root"/>
        <property name="password" value="123456"/>
      </bean>

    <!-- 注册数据源:C3P0-->
    <!-- <bean id="myDataSource" class="org.mchange.v2.c3p0.ComboPooledDataSource">
      <property name="driverClass" value="${jdbc.driver}"/>
      <property name="jdbcUrl" value="${jdbc.url}"/>
      <property name="user" value="${jdbc.user}"/>
      <property name="password" value="${jdbc.password}"/>
    </bean> -->

    <!-- 注册属性文件:方式一 -->
    <!--
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
      <property name="location" value="classpath:jdbc.properties"/>
    </bean> -->

    <!-- 注册属性文件:方式二 -->
    <context:property-placeholder location="classpath:jdbc.properties"/>

    <!-- 注册JdbcTemplate -->
    <!--
      <bean id="myJdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="myDataSource"/>
      </bean>
    -->

  • 相关阅读:
    华硕路由器修改 Hosts 以达到局域网内自定义解析
    一款开源、高颜值的终端terminus,支持Windows、MacOS
    Windows 10启用Linux子系统(WSL)
    一款全能的下载工具Motrix,支持BT、磁力链、百度网盘等资源
    ubuntu 14.04 和16.04 快速下载
    CentOS 7一键安装Seafile搭建私有云存储
    background背景色
    3d爱心代码
    Mac Mini(late 2014) 添加NVMe固态组Fusion Drive
    member access within misaligned address 0x0000002c3931 for type 'struct ListNode‘
  • 原文地址:https://www.cnblogs.com/hwgok/p/8018304.html
Copyright © 2020-2023  润新知