- Spring Essentials
- Shameer Kunjumohamed Hamidreza Sattari
- 88字
- 2021-07-16 13:05:48
Externalizing properties with PropertyPlaceholderConfigurer
PropertyPlaceholderConfigurer
is another convenient utility to externalize property values from a bean definition into a separate file that uses the standard java.util.Properties
format. It replaces placeholders in XML bean definitions with matching property values in the configured property file, as shown here. This is the best way to externalize profile or environment-specific information such as datasource config, e-mail settings, and so on. The DevOps team will just edit these property files and never mess with your code:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations" value="classpath:datasource.properties"/> </bean> <bean id="dataSource" destroy-method="close" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/> </bean>
Here is another simpler declaration of PropertyPlaceholder
:
<context:property-placeholder location="classpath:datasource.properties"/>
推薦閱讀
- Python概率統計
- Mastering Ember.js
- Python Network Programming Cookbook(Second Edition)
- Full-Stack Vue.js 2 and Laravel 5
- Learning ELK Stack
- 區塊鏈技術進階與實戰(第2版)
- ScratchJr趣味編程動手玩:讓孩子用編程講故事
- MATLAB GUI純代碼編寫從入門到實戰
- C語言程序設計習題與實驗指導
- Android編程權威指南(第4版)
- Java多線程并發體系實戰(微課視頻版)
- 跟小樓老師學用Axure RP 9:玩轉產品原型設計
- JSP應用與開發技術(第3版)
- Java程序性能優化實戰
- Learning Azure DocumentDB