Biz I'm a junior in the fantastic world of java, all these drips are ref from tutorials. And if someone asks me how or why it should be, I will smile a bitter smile. This article is for my reference afterwards. If any concern, pls kindly let me known. Thanks and regards! Eric
M-1
class="java">
xmlns:util="http://www.springframework.org/schema/util
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util.xsd
<util:properties id="db" location="classpath:db.properties"/>
<bean id="dbinfo" class="com.eric.june30.spel.DbInfo">
<property name="driver" value="#{db['driver']}"/>
<property name="url" value="#{db['url']}"/>
<property name="userName" value="#{db['username']}"/>
<property name="password" value="#{db['password']}"/>
</bean>
public class DbInfo {
private String driver;
private String url;
private String userName;
private String password;
……
}
driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@localhost:1521:ora
username=eric
password=eirc
M-2
server=Eric.ora
Eric.ora.driver=oracle.jdbc.driver.OracleDriver
Eric.ora.url=jdbc:oracle:thin:@localhost:1521:ora
Eric.ora.username=eric
Eric.ora.password=eric
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:db.properties</value>
</list>
</property>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="${${server}.driver}"></property>
<property name="username" value="${${server}.username}"></property>
<property name="password" value="${${server}.password}"></property>
<property name="url" value="${${server}.url}"></property>
</bean>