spring配置文件读取jdbc.properties的配置信息

阳光穿透心脏的1/2处 2022-07-14 08:14 439阅读 0赞
  1. 时间:2016-12-3

内容:spring读取jdbc.properties的配置信息;

一.jdbc.properties的配置信息

jdbc.properties的配置信息主要包括用户名、密码以及连接池的一些配置,代码如下:

  1. jdbc.driverClassName=com.mysql.jdbc.Driver
  2. #jdbc.url=jdbc\:mysql\://172.18.73.253\:3307/network
  3. jdbc.url=jdbc\:mysql\://127.0.0.1\:3306/webwork
  4. #jdbc.url=jdbc\:mysql\://172.18.73.5\:3306/webwork
  5. jdbc.username=root
  6. jdbc.password=root
  7. jdbc.initialPoolSize=20
  8. jdbc.maxPoolSize=100
  9. jdbc.minPoolSize=10
  10. jdbc.maxIdleTime=600
  11. jdbc.acquireIncrement=5
  12. jdbc.maxStatements=50
  13. jdbc.idleConnectionTestPeriod=60

二、 在applicationContext.xml中怎么读取jdbc.properties的配置信息;

废话少说,直接上代码,代码如下:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans
  3. xmlns="http://www.springframework.org/schema/beans"
  4. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5. xmlns:p="http://www.springframework.org/schema/p"
  6. xmlns:context="http://www.springframework.org/schema/context"
  7. xmlns:aop="http://www.springframework.org/schema/aop"
  8. xmlns:tx="http://www.springframework.org/schema/tx"
  9. xmlns:mvc="http://www.springframework.org/schema/mvc"
  10. xsi:schemaLocation="http://www.springframework.org/schema/beans
  11. http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
  12. http://www.springframework.org/schema/context
  13. http://www.springframework.org/schema/context/spring-context-4.1.xsd
  14. http://www.springframework.org/schema/tx
  15. http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
  16. http://www.springframework.org/schema/aop
  17. http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
  18. http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring
  19. http://ehcache-spring-annotations.googlecode.com/svn/schema/ehcache-spring/ehcache-spring-1.1.xsd
  20. http://www.springframework.org/schema/mvc
  21. http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
  22. <!-- 加载jdbc.properties配置文件 -->
  23. <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  24. <property name="locations">
  25. <list>
  26. <value>classpath:jdbc.properties</value>
  27. </list>
  28. </property>
  29. </bean>
  30. <!-- c3p0数据源配置方式-->
  31. <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
  32. destroy-method="close"
  33. p:driverClass="${jdbc.driverClassName}"
  34. p:jdbcUrl="${jdbc.url}"
  35. p:user="${jdbc.username}"
  36. p:password="${jdbc.password}"
  37. p:maxPoolSize="${jdbc.maxPoolSize}"
  38. p:minPoolSize="${jdbc.minPoolSize}"
  39. p:initialPoolSize="${jdbc.initialPoolSize}"
  40. p:maxIdleTime="${jdbc.maxIdleTime}"
  41. p:acquireIncrement="${jdbc.acquireIncrement}"
  42. p:maxStatements="${jdbc.maxStatements}"
  43. p:idleConnectionTestPeriod="${jdbc.idleConnectionTestPeriod}"
  44. />

在此 推荐一篇spring 读取jdbc.properties的文章: 点击打开链接

发表评论

表情:
评论列表 (有 0 条评论,439人围观)

还没有评论,来说两句吧...

相关阅读