DB configuration with properties file_JAVA_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > JAVA > DB configuration with properties file

DB configuration with properties file

 2013/7/13 0:14:42  eric2500  程序员俱乐部  我要评论(0)
  • 摘要:BizI'majuniorinthefantasticworldofjava,allthesedripsarereffromtutorials.Andifsomeoneasksmehoworwhyitshouldbe,Iwillsmileabittersmile.Thisarticleisformyreferenceafterwards.Ifanyconcern,plskindlyletmeknown.Thanksandregards!EricM-1xmlns:util="http://www
  • 标签:file
       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>
上一篇: java完整版本获取客户端有效IP 下一篇: 没有下一篇了!
发表评论
用户名: 匿名