- 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"/>
推薦閱讀
- Web應用系統開發實踐(C#)
- Spring Cloud Alibaba微服務架構設計與開發實戰
- 深入淺出Electron:原理、工程與實踐
- 大學計算機基礎實驗教程
- 編寫整潔的Python代碼(第2版)
- FreeSWITCH 1.6 Cookbook
- 網頁設計與制作教程(HTML+CSS+JavaScript)(第2版)
- 新編Premiere Pro CC從入門到精通
- Building Serverless Applications with Python
- 深度學習原理與PyTorch實戰(第2版)
- PHP 7從零基礎到項目實戰
- R Data Science Essentials
- Mastering Gephi Network Visualization
- AI自動化測試:技術原理、平臺搭建與工程實踐
- Software-Defined Networking with OpenFlow(Second Edition)