zoukankan      html  css  js  c++  java
  • spring常见引入数据源的几种方式

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context.xsd">





    <!--引入外部属性文件-->
    <context:property-placeholder location="classpath:jdbc.properties"></context:property-placeholder>
    <!--c3p0 数据源-->
    <bean id="c3p0DataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    <property name="driverClass" value="${jdbc.driver}"></property>
    <property name="jdbcUrl" value="${jdbc.url}"></property>
    <property name="user" value="${jdbc.user}"></property>
    <property name="password" value="${jdbc.password}"></property>
    </bean>
    <!--dbcp 数据源-->
    <bean id="dbcpDatSource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${jdbc.driver}"></property>
    <property name="url" value="${jdbc.url}"></property>
    <property name="username" value="${jdbc.user}"></property>
    <property name="password" value="${jdbc.password}"></property>
    </bean>
    <!--spring自带 数据源-->
    <bean id="springDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${jdbc.driver}"></property>
    <property name="url" value="${jdbc.url}"></property>
    <property name="username" value="${jdbc.user}"></property>
    <property name="password" value="${jdbc.password}"></property>
    </bean>
    <!--创建jdbc 模板-->
    <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="springDataSource"></property>
    </bean>
    </beans>
  • 相关阅读:
    五、Django的模板渲染和继承
    四、Django的views
    三、Django的urls
    ubuntu超过4G如何备份成iso文件
    15张vim速查表
    这样配置你的IDEA工作效率提高好几倍!
    git用法
    数据库 | MySQL日志管理
    异常处理
    池 concurrent.futrues
  • 原文地址:https://www.cnblogs.com/dragonyl/p/11153320.html
Copyright © 2011-2022 走看看