- 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"/>
推薦閱讀
- Java異步編程實戰
- Learning AWS Lumberyard Game Development
- 網頁設計與制作教程(HTML+CSS+JavaScript)(第2版)
- Access 2010數據庫基礎與應用項目式教程(第3版)
- Backbone.js Blueprints
- IBM Cognos Business Intelligence 10.1 Dashboarding cookbook
- jQuery技術內幕:深入解析jQuery架構設計與實現原理
- 青少年學Python(第2冊)
- Python機器學習開發實戰
- Mastering PowerCLI
- Spark技術內幕:深入解析Spark內核架構設計與實現原理
- 基于JavaScript的WebGIS開發
- 軟技能2:軟件開發者職業生涯指南
- Scratch編程入門與算法進階(第2版)
- Selenium自動化測試實戰:基于Python