Spring配置文件中如何配置数据库连接
xml配置文件中配置如下:
<spring:bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <spring:property name="locations"> <spring:list> <spring:value>classpath:conf/jdbc.properties</spring:value> </spring:list> </spring:property> </spring:bean> <spring:bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <spring:property name="driverClassName" value="${jdbc.driverClassName}" /> <spring:property name="url" value="${jdbc.url}" /> <spring:property name="username" value="${jdbc.username}" /> <spring:property name="password" value="${jdbc.password}" /> <spring:property name="maxActive" value="30" /> <spring:property name="maxIdle" value="10" /> <spring:property name="maxWait" value="1000" /> <spring:property name="defaultAutoCommit" value="true" /> </spring:bean>
jdbc.properties配置文件中连接数据库配置:
#sqlserver数据源配置 jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver jdbc.url=jdbc:sqlserver://192.168.1.60:1408;DatabaseName=test jdbc.username=sa jdbc.password=1 #mysql数据源配置 jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://192.168.1.60:3306/test jdbc.username=root jdbc.password=root #Oracle数据源配置 jdbc.driverClassName=oracle.jdbc.driver.OracleDriver jdbc.url=jdbc:oracle:thin:@10.60.17.9:1521:orcl jdbc.username=admin jdbc.password=admin
相关推荐
yangkang 2020-11-09
lbyd0 2020-11-17
sushuanglei 2020-11-12
85477104 2020-11-17
KANSYOUKYOU 2020-11-16
wushengyong 2020-10-28
lizhengjava 2020-11-13
星月情缘 2020-11-13
huangxiaoyun00 2020-11-13
luyong0 2020-11-08
腾讯soso团队 2020-11-06
Apsaravod 2020-11-05
PeterChangyb 2020-11-05
gaobudong 2020-11-04
wwwjun 2020-11-02
gyunwh 2020-11-02
EchoYY 2020-10-31
dingyahui 2020-10-30