springconfig動態(tài)修改 springboot如何讀取自定義配置項?
springboot如何讀取自定義配置項?網(wǎng)站總是需要使用一些自定義配置,我把它放在一個屬性文件,如:config。此文件與struts一起放置。XML,在我的Src中。1.創(chuàng)建一個新的工具類prop
springboot如何讀取自定義配置項?
網(wǎng)站總是需要使用一些自定義配置,我把它放在一個屬性文件,如:config。此文件與struts一起放置。XML,在我的Src中。
1.創(chuàng)建一個新的工具類propertiesutil并在其中定義一個公共靜態(tài)Java。
util.properties類的對象[PPS
2。創(chuàng)建新的偵聽類webconfiglistener并實現(xiàn)servletcontextlistener
public void contextinitialized(servletcontextevent arg0){
propertiesutil的接口。
pps=new Properties()
試試{
String path=(getClass().getClassLoader().getResource(“”).toURI()).getPath()
FileInputStream fis=new FileInputStream(path“config.
Properties”)
PropertiesUtil.pps.load(fis)
}catch(Exception e){
e.printStackTrace()
}
3.在網(wǎng)狀物。將webconfiglistener添加到XML
com。
phonesale.common.WebConfigListener
4.讀取程序配置時使用:propertiesutil。Getproperty(key)
編輯特別推薦:
Java對話框的字體設(shè)置
Java開發(fā)守護進程
深入Java核心:JVM中的堆棧和局部變量。