- 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"/>
推薦閱讀
- 極簡算法史:從數學到機器的故事
- Fundamentals of Linux
- 小創客玩轉圖形化編程
- 軟件測試項目實戰之性能測試篇
- Mastering Rust
- Reactive Android Programming
- 信息技術應用基礎
- Learning Apache Mahout Classification
- PySide 6/PyQt 6快速開發與實戰
- Mastering Unity 2D Game Development(Second Edition)
- 匯編語言編程基礎:基于LoongArch
- 從零開始學算法:基于Python
- 你好!Python
- 區塊鏈:技術與場景
- C++ Game Development Cookbook