• spring项目中使用alibaba.druid.pool.DruidDataSource来装载oracle数据源


    0、编写配置文件

    jdbc.type=oracle
    jdbc.driver=oracle.jdbc.driver.OracleDriver
    jdbc.url=jdbc:oracle:thin:@192.168.2.9:1521/orcl
    jdbc.username=xbs
    jdbc.password=xbs

    1、spring-context.xml中装载配置文件(记得把configName改成你的文件名称,一般问jdbc.properties或者项目名.properties)

    <!-- 加载应用属性实例,可通过 @Value("#{APP_PROP['jdbc.driver']}") String jdbcDriver 方式引用 -->
        <util:properties id="APP_PROP" location="classpath:configName.properties" local-override="true" />

    2、spring-contex.xmlt中配置数据源

        <!-- 数据源配置, 使用 BoneCP 数据库连接池 -->
        <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
            <!-- 数据源驱动类可不写,Druid默认会自动根据URL识别DriverClass -->
            <property name="driverClassName" value="${jdbc.driver}" />
    
            <!-- 基本属性 url、user、password -->
            <property name="url" value="${jdbc.url}" />
            <property name="username" value="${jdbc.username}" />
            <property name="password" value="${jdbc.password}" />
    
            <!-- 配置初始化大小、最小、最大 -->
            <property name="initialSize" value="${jdbc.pool.init}" />
            <property name="minIdle" value="${jdbc.pool.minIdle}" />
            <property name="maxActive" value="${jdbc.pool.maxActive}" />
    
            <!-- 配置获取连接等待超时的时间 -->
            <property name="maxWait" value="60000" />
    
            <!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
            <property name="timeBetweenEvictionRunsMillis" value="60000" />
    
            <!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
            <property name="minEvictableIdleTimeMillis" value="300000" />
    
            <property name="validationQuery" value="${jdbc.testSql}" />
            <property name="testWhileIdle" value="true" />
            <property name="testOnBorrow" value="false" />
            <property name="testOnReturn" value="false" />
    
            <!-- 打开PSCache,并且指定每个连接上PSCache的大小(Oracle使用) -->
            <property name="poolPreparedStatements" value="true" />
            <property name="maxPoolPreparedStatementPerConnectionSize" value="20" />
    
            <!-- 配置监控统计拦截的filters -->
            <property name="filters" value="stat" />
        </bean>

    附加:头信息

    <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"
        xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
        xmlns:util="http://www.springframework.org/schema/util" xmlns:task="http://www.springframework.org/schema/task"
        xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
            http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.1.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.1.xsd
            http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-4.1.xsd"
        default-lazy-init="true">
  • 相关阅读:
    [BZOJ1620][Usaco2008 Nov]Time Management 时间管理
    [BZOJ1634][Usaco2007 Jan]Protecting the Flowers 护花
    [BZOJ1725][Usaco2006 Nov]Corn Fields牧场的安排
    [BZOJ1708][Usaco2007 Oct]Money奶牛的硬币
    [BZOJ1690][Usaco2007 Dec]奶牛的旅行
    fzu 2132 LQX的作业
    fzu 2139 久违的月赛之二
    poj 1849 Two 树形dp
    师范大学 e: skyscrapers
    O(∩_∩)O~~
  • 原文地址:https://www.cnblogs.com/404code/p/10824067.html
Copyright © 2020-2023  润新知