標籤:1.0 http config url root drive val jdbc 方式
Spring beans使用參數預留位置(JDBC配置讀取樣本)
beans.xml設定檔
<?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:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:property-placeholder location="db.properties"/> <!-- 預留位置 得配置方式--> <bean id="dbUtil" class="com.my.util.DBUtil"> <property name="driverName" value="${driverName}"/> <property name="url" value="${url}"/> <property name="username" value="${username}" /> <property name="pwd" value="${pwd}"/> </bean> <!-- 註冊propertyPlaceholderConfigurer對象-> <bean id="propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" > <property name="locations"> <list> <value>db.properties</value> </list> </property> </bean> --> </beans>
db.properties 設定檔
driverName=com.mysql.jdbc.Driverurl=jdbc:mysql://127.0.0.1:3306/jg29username=rootpwd=root
(# 降低耦合度,符合開閉原則【對拓展開、對修改源碼閉】)
JavaEE筆記(十一)