更新時間:2020-05-25 16:07:09 來源:動力節點 瀏覽2319次
Java代碼
String?host=(String)?CustomizedPropertyPlaceholderConfigurer.getContextProperty("mail.smtp.host");
Java代碼
?import?java.util.HashMap;?
??import?java.util.Map;?
??import?java.util.Properties;?
???
??import?org.springframework.beans.BeansException;?
??import?org.springframework.beans.factory.config.ConfigurableListableBeanFactory;?
??import?org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;?
???
??/**
???*?自定義PropertyPlaceholderConfigurer返回properties內容
??*?
???*?@author?LHY?2012-02-24
???*?
???*/?
??public?class?CustomizedPropertyPlaceholderConfigurer?extends?
??????????PropertyPlaceholderConfigurer?{?
???
??????private?static?Map<String,?Object>?ctxPropertiesMap;?
???
??????@Override?
??????protected?void?processProperties(?
??????????????ConfigurableListableBeanFactory?beanFactoryToProcess,?
??????????????Properties?props)?throws?BeansException?{?
??????????super.processProperties(beanFactoryToProcess,?props);?
??????????ctxPropertiesMap?=?new?HashMap<String,?Object>();?
??????????for?(Object?key?:?props.keySet())?{?
??????????????String?keyStr?=?key.toString();?
??????????????String?value?=?props.getProperty(keyStr);?
??????????????ctxPropertiesMap.put(keyStr,?value);?
??????????}???
??????}?
?
??????public?static?Object?getContextProperty(String?name)?{?
??????????return?ctxPropertiesMap.get(name);?
??????}?
??}
Xml代碼
<bean?id="propertyConfigurer"?
??????class="com.tjsoft.base.util.CustomizedPropertyPlaceholderConfigurer">?
??????<property?name="ignoreResourceNotFound"?value="true"?/>?
??????<property?name="locations">?
??????????<list>?
??????????????<value>/WEB-INF/config/jdbc.properties</value>?
??????????????<value>/WEB-INF/config/mail.properties</value>?
??????????????<value>/WEB-INF/config/system.properties</value>?
??????????</list>?
??????</property>?
??</bean>
以上就是動力節點java培訓機構的小編針對“如何獲取java配置properties文件”的內容進行的回答,希望對大家有所幫助,如有疑問,請在線咨詢,有專業老師隨時為你服務。
0基礎 0學費 15天面授
有基礎 直達就業
業余時間 高薪轉行
工作1~3年,加薪神器
工作3~5年,晉升架構
提交申請后,顧問老師會電話與您溝通安排學習