spring.xml从外部文件引入数据库配置信息

 1     <!-- 分散配置 -->
 2     <context:property-placeholder location="classpath:jdbc.properties" />
 3 
 4     <!-- 数据源 -->
 5     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
 6         <property name="driverClass" value="${jdbc.driverclass}" />
 7         <property name="jdbcUrl" value="${jdbc.url}"></property>
 8         <property name="user" value="${jdbc.username}" />
 9         <property name="password" value="${jdbc.password}" />
10 
11         <property name="maxPoolSize" value="${c3p0.pool.size.max}" />
12         <property name="minPoolSize" value="${c3p0.pool.size.min}" />
13         <property name="initialPoolSize" value="${c3p0.pool.size.ini}" />
14         <property name="acquireIncrement" value="${c3p0.pool.size.increment}" />
15     </bean>

jdbc.properties

 1 jdbc.driverclass=com.mysql.jdbc.Driver
 2 jdbc.url=jdbc:mysql://localhost:3306/springmvcdb?characterEncoding=utf-8
 3 jdbc.username=root
 4 jdbc.password=root
 5 
 6 c3p0.pool.size.max=10
 7 c3p0.pool.size.min=2
 8 c3p0.pool.size.ini=3
 9 c3p0.pool.size.increment=2
10 
11 hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
12 hibernate.show_sql=true

 

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
 4     xmlns:mvc="http://www.springframework.org/schema/mvc"
 5     xmlns:context="http://www.springframework.org/schema/context"
 6     xmlns:aop="http://www.springframework.org/schema/aop" 
 7     xmlns:tx="http://www.springframework.org/schema/tx"
 8     xsi:schemaLocation="http://www.springframework.org/schema/beans 
 9                         http://www.springframework.org/schema/beans/spring-beans-3.2.xsd 
10                         http://www.springframework.org/schema/mvc 
11                         http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd 
12                         http://www.springframework.org/schema/context 
13                         http://www.springframework.org/schema/context/spring-context-3.2.xsd
14                         http://www.springframework.org/schema/aop 
15                         http://www.springframework.org/schema/aop/spring-aop-3.2.xsd 
16                         http://www.springframework.org/schema/tx 
17                         http://www.springframework.org/schema/tx/spring-tx-3.2.xsd ">
View Code

 

posted on 2014-06-21 21:17  wf110  阅读(1451)  评论(0编辑  收藏  举报