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();
}
}

spring4笔记----PropertyPlaceholderConfigurer 属性占位符配置器的更多相关文章

  1. spring4笔记----PropertyOverrideConfigureer 重写占位符配置器(图)

  2. 8 -- 深入使用Spring -- 1...4 属性占位符配置器

    8.1.4 属性占位符配置器 PropertyPlaceholderConfigurer 是一个容器后处理器,负责读取Properties属性文件里的属性值,并将这些属性值设置成Spring配置文件的 ...

  3. 8 -- 深入使用Spring -- 1...4 重写占位符配置器

    8.1.5 重写占位符配置器 (PropertyOverrideConfigurer) PropertyOverrideConfigurer是Spring提供的另一个容器后处理器.PropertyOv ...

  4. Spring属性占位符 PropertyPlaceholderConfigurer

    http://www.cnblogs.com/yl2755/archive/2012/05/06/2486752.html PropertyPlaceholderConfigurer是个bean工厂后 ...

  5. 【mybatis源码学习】mybtias基础组件-占位符解析器

    一.占位符解析器源码 1.占位符解析器实现的目标 通过解析字符串中指定前后缀中的字符,并完成相应的功能. 在mybtias中的应用,主要是为了解析Mapper的xml中的sql语句#{}中的内容,识别 ...

  6. Spring(3.2.3) - Beans(12): 属性占位符

    使用属性占位符可以将 Spring 配置文件中的部分元数据放在属性文件中设置,这样可以将相似的配置(如 JDBC 的参数配置)放在特定的属性文件中,如果只需要修改这部分配置,则无需修改 Spring ...

  7. SpringBoot环境属性占位符解析和类型转换

    前提 前面写过一篇关于Environment属性加载的源码分析和扩展,里面提到属性的占位符解析和类型转换是相对复杂的,这篇文章就是要分析和解读这两个复杂的问题.关于这两个问题,选用一个比较复杂的参数处 ...

  8. Spring - IoC(12): 属性占位符

    使用属性占位符可以将 Spring 配置文件中的部分元数据放在属性文件中设置,这样可以将相似的配置(如 JDBC 的参数配置)放在特定的属性文件中,如果只需要修改这部分配置,则无需修改 Spring ...

  9. Spring实战(八)bean装配的运行时值注入——属性占位符和SpEL

    前面涉及到依赖注入,我们一般哦都是将一个bean引用注入到另一个bean 的属性or构造器参数or Setter参数,即将为一个对象与另一个对象进行关联. bean装配的另一个方面是指将一个值注入到b ...

随机推荐

  1. Deeplearning.ai课程笔记--汇总

    从接触机器学习就了解到Andrew Ng的机器学习课程,后来发现又出来深度学习课程,就开始在网易云课堂上学习deeplearning.ai的课程,Andrew 的课真是的把深入浅出.当然学习这些课程还 ...

  2. javaScript之分支判断与内置对象

    一,分支结构 单一选择结构(if) 二路选择结构(if/else) 内联三元运算符 ?: 多路选择结构(switch) 1.1  if 控制语句 if-else基本格式: if (表达式){ 语句1; ...

  3. Nodejs sublime text 3安装与配置

    1.下载subline的nodejs插件 2.解压zip文件, 并重命名文件夹“Nodejs” 3.  打开sublime,操作"preference" --> " ...

  4. Linux核心命令

    Linux核心命令 strace(查看系统调用的一个过程) 例:strace cat /test.txt netstat perf top pidstat mpstat dstat vmstat sl ...

  5. CLR via c# 值类型“不可变”

    昨天看书看到引用类型和值类型,书中讲到值类型“不可变”,如图: 看了两遍没怎么看懂,又仔细多看了几遍,说下我的理解: 比如说一个int类型有几个成员, MaxValue.MinValue的值是不可变的 ...

  6. 【Java每日一题】20170315

    20170314问题解析请点击今日问题下方的“[Java每日一题]20170315”查看(问题解析在公众号首发,公众号ID:weknow619) package Mar2017; public cla ...

  7. [算法总结] 13 道题搞定 BAT 面试——字符串

    1. KMP 算法 谈到字符串问题,不得不提的就是 KMP 算法,它是用来解决字符串查找的问题,可以在一个字符串(S)中查找一个子串(W)出现的位置.KMP 算法把字符匹配的时间复杂度缩小到 O(m+ ...

  8. Spring Boot依赖引入的多种方式

    使用Spring Boot开发,不可避免的会面临Maven依赖包版本的管理. 有如下几种方式可以管理Spring Boot的版本. 使用parent继承 <?xml version=" ...

  9. 我从Angular 2转向Vue.js, 也没有选择React

    译者按: 通过使用Angular的经历,作者已经完全转为Vue粉了!我们Fundebug目前还是用AngularJS 1,坦白说,学习曲线蛮陡的. 原文: Why we moved from Angu ...

  10. mybatis加载属性

    1): <dataSource>的<property>标签加载属性 在 properties 元素体内定义的属性首先被读取 然后会读取 properties 元素中 resou ...