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>
  • 相关阅读:
    Linux的上的MongoDB的安装与卸载
    MongoDB常用操作
    scrapy 爬网站 显示 Filtered offsite request to 错误.
    在linux系统下把多个终端合并在一个窗口
    安装python爬虫scrapy踩过的那些坑和编程外的思考
    大规模爬虫流程总结
    Python的35种“黑魔法”级别技巧!
    2019/2/13 Python今日收获
    2019/2/12 Python今日收获
    2019/1/22 Python今日收获
  • 原文地址:https://www.cnblogs.com/dragonyl/p/11153320.html
Copyright © 2011-2022 走看看