1、配置xml文件

<?xml version="1.0" encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <context:property-placeholder location="classpath:db.properties"/> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
<property name="user" value="${user}"></property>
<property name="password" value="${password}"></property>
<property name="driverClass" value="${driverclass}"></property>
<property name="jdbcUrl" value="${jdbcurl}"></property>
</bean> </beans>

2、外部配置文件

user=root
password=admin
driverclass=com.mysql.jdbc.Driver
jdbcUrl=jdbc:mysql:///authority

3、main方法

package com.spring.properties;

import java.sql.SQLException;

import javax.sql.DataSource;

import org.springframework.context.*;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class Main {
public static void main(String[] args) throws SQLException {
ApplicationContext ctx = new ClassPathXmlApplicationContext("bean-properties.xml"); DataSource dataSource = (DataSource)ctx.getBean("dataSource");
System.out.println(dataSource.getConnection());
}
}

最新文章

  1. N皇后问题
  2. .Net中的加密解密
  3. git之一
  4. Liferay 6.2 改造系列之七:关闭使用条款确认、密码提醒、新用户强制修改密码等功能
  5. 微信网页授权,微信登录,oauth2
  6. Ajax实现联动效果
  7. Ceph的客户端安装
  8. 深入理解Android内存管理原理(六)
  9. linux就是这个范儿之融于心而表于行(1)
  10. dtrace4linux_Example
  11. EF搭建可扩展菜单
  12. 【原创】Java基础之Session机制
  13. 转 freemarker macro(宏)的使用
  14. centos7更改网卡名称
  15. Hanlp1.7版本的新增功能一览
  16. JavaScript 模拟 HashMap例子
  17. 14. Longest Common Prefix(暴力循环)
  18. 几个方便的nodejs 任务调度框架
  19. oracle A用户访问B用户的表aa
  20. Matlab的集合运算[转]

热门文章

  1. Remember the Word
  2. C++编程中对缓冲区的理解(OS默认4096大小的缓冲区,有例子,很形象)
  3. moveToThread的最简单用法(依葫芦画瓢即可)(使得线程也更偏向于信号槽的使用方法)
  4. SVN项目库错误Unsupported FS format svn: Expected FS format between &#39;1&#39; and &#39;4&#39;; found format &#39;6&#39;
  5. Event — Windows API
  6. Swift基础语法学习总结一
  7. ubunu设置java命令为全局的命令-添加到全局环境变量
  8. C++ —— 非常量引用不能指向临时对象
  9. motan源码分析八:涉及到底层的客户端调用
  10. Oracle&amp;#39;s Business Intelligence Applications Configuration Manager 基本概念