spring配置文件读取jdbc.properties的配置信息
2016-12-03 14:33
846 查看
时间:2016-12-3
内容:spring读取jdbc.properties的配置信息;
一.jdbc.properties的配置信息
jdbc.properties的配置信息主要包括用户名、密码以及连接池的一些配置,代码如下:
jdbc.driverClassName=com.mysql.jdbc.Driver #jdbc.url=jdbc\:mysql\://172.18.73.253\:3307/network jdbc.url=jdbc\:mysql\://127.0.0.1\:3306/webwork #jdbc.url=jdbc\:mysql\://172.18.73.5\:3306/webwork jdbc.username=root jdbc.password=root jdbc.initialPoolSize=20 jdbc.maxPoolSize=100 jdbc.minPoolSize=10 jdbc.maxIdleTime=600 jdbc.acquireIncrement=5 jdbc.maxStatements=50 jdbc.idleConnectionTestPeriod=60
二、 在applicationContext.xml中怎么读取jdbc.properties的配置信息;
废话少说,直接上代码,代码如下:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" 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/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd"> <!-- 加载jdbc.properties配置文件 --> <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:jdbc.properties</value> </list> </property> </bean> <!-- c3p0数据源配置方式--> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" p:driverClass="${jdbc.driverClassName}" p:jdbcUrl="${jdbc.url}" p:user="${jdbc.username}" p:password="${jdbc.password}" p:maxPoolSize="${jdbc.maxPoolSize}" p:minPoolSize="${jdbc.minPoolSize}" p:initialPoolSize="${jdbc.initialPoolSize}" p:maxIdleTime="${jdbc.maxIdleTime}" p:acquireIncrement="${jdbc.acquireIncrement}" p:maxStatements="${jdbc.maxStatements}" p:idleConnectionTestPeriod="${jdbc.idleConnectionTestPeriod}" />
在此推荐一篇spring读取jdbc.properties的文章: 点击打开链接
相关文章推荐
- 【Java学习之代码学习】 Prog11_三数排序问题
- 实现在eclipse中编译ns-3的详细步骤
- 基于JDK动态代理和CGLIB动态代理的实现Spring注解管理事务(@Trasactional)到底有什么区别。
- 创建完maven工程之后,提示[FATAL_ERROR] Cannot start Maven: Project JDK is not specified. <a href=''>Configure</a>
- 设置Eclipse的workspace路径
- JAVA循环冗余校验(CRC32)
- Java 8新特性 内建函数式接口详解
- Java 8新特性方法引用详细介绍
- SpringCloud Hystrix 断路器
- IO流(2)
- Java Web程序开发入门--读书笔记(五)
- Java基础:请求重定向与请求转发的比较
- java线程同步简单介绍
- SpringMVC 整合 百度编辑器UEditor
- SNF开发平台WinForm之十-Excel导入-SNF快速开发平台3.3-Spring.Net.Framework
- SNF开发平台WinForm之九-代码生成器使用说明-SNF快速开发平台3.3-Spring.Net.Framework
- Maven创建EJB项目HelloWorld使用IDE为eclipse
- Spring注解hibernate实体类bean
- 遍历HashMap的四种方法
- SNF开发平台WinForm之八-自动升级程序部署使用说明-SNF快速开发平台3.3-Spring.Net.Framework