DB configuration with properties file
2658 단어 자바
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
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>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.