• spring4笔记----PropertyPlaceholderConfigurer 属性占位符配置器


    driverClassName=com.mysql.jdbc.Driver
    url=jdbc:mysql://localhost:3306/spring
    username=root
    password=123456
    <!-- 
    --------PropertyOverrideConfigurer ------------------
    dataSource.driverClass=com.mysql.jdbc.Driver
    dataSource.jdbcUrl=jdbc:mysql://localhost:3306/spring
    dataSource.user=root
    dataSource.password=123456
    
    
    
     -->
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://www.springframework.org/schema/beans"
        xmlns:p="http://www.springframework.org/schema/p"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-4.3.xsd">
    <!--<bean class="org.springframework.beans.factory.config.PropertyOverrideConfigurer">  -->
    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
    <list>
    <value>dataSource.properties</value>
    </list>
    </property>
    </bean>
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"
     p:driverClass="${driverClassName}" p:jdbcUrl="${url}" p:user="${username}" p:password="${password}"
    />
    </beans>

    package com.ij34.bean;
    import java.sql.*;
    import javax.sql.DataSource;
    
    import org.springframework.context.*;
    import org.springframework.context.support.*;
    
    public class test {
    
    public static void main(String[] args) throws Exception {
       @SuppressWarnings("resource")
    ApplicationContext  ac=new ClassPathXmlApplicationContext("beans.xml");
       DataSource ds=(DataSource) ac.getBean("dataSource");
       Connection conn=ds.getConnection();
       PreparedStatement ps= conn.prepareStatement("insert into news_inf value(null,?,?)");
       ps.setString(1, "加油2017");
       ps.setString(2, "2017,这是挑战与机遇的一年!");
       ps.executeUpdate();
       ps.close();
       conn.close();
    }
    }
  • 相关阅读:
    结婚很难
    ***归心似箭***
    听首你家健和我家菲都唱过的歌吧
    努力幸福
    080509
    快速切题 poj1573
    POJ 2586 Y2K Accounting Bug 贪心 难度:2
    快速切题 poj2632
    POJ 3579 median 二分搜索,中位数 难度:3
    HDU 4802 && HDU 4803 贪心,高精 && HDU 4804 轮廓线dp && HDU 4805 计算几何 && HDU 4811 (13南京区域赛现场赛 题目重演A,B,C,D,J)
  • 原文地址:https://www.cnblogs.com/tk55/p/6507454.html
Copyright © 2020-2023  润新知