更新时间:2023-11-24 20:35:46
使用Spring(在XML中进行显式连接,自动装配或它们的某种组合)来定义常量"配置,然后将其余部分外部化到属性文件中.数据库凭证是这种情况的常见示例.
Use Spring, being explicit wiring in XML, auto-wiring or some combination thereof, to define "constant" config and then externalize the rest in properties files. Database credentials are a common example of this.
有关基准,请参见 Spring和Ibatis教程这个例子.简短版本:
See Spring and Ibatis Tutorial for a baseline example of this. Short version:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:database.properties"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${database.class}"/>
<property name="url" value="${database.url}"/>
<property name="username" value="${database.username}"/>
<property name="password" value="${database.password}"/>
</bean>
with database.properties(在类路径中):
with database.properties (in the classpath):
database.username=scratch
database.password=scratch
database.class=oracle.jdbc.OracleDriver
database.url=jdbc:oracle:thin:@localhost:1521:XE