精品专区-精品自拍9-精品自拍三级乱伦-精品自拍视频-精品自拍视频曝光-精品自拍小视频

網(wǎng)站建設(shè)資訊

NEWS

網(wǎng)站建設(shè)資訊

如何解決spring無法讀取properties文件數(shù)據(jù)問題

本篇文章為大家展示了如何解決spring無法讀取properties文件數(shù)據(jù)問題,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。

息縣網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián),息縣網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為息縣上千多家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營(yíng)銷網(wǎng)站建設(shè)要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的息縣做網(wǎng)站的公司定做!

1. controller中無法讀取config.properties文件

controller中注入的@Value配置是從servlet-context.xml配置文件中獲取的;service中注入的@Value配置可以從applicationContext.xml中獲取的。所以,如果要在controller中注入屬性配置,需要在相應(yīng)servlet文件中添加配置,同applicationContext.xml中一樣。

            classpath:jdbc.properties      classpath:config.properties        

2.service中無法讀取config.properties文件

查看配置文件是否有多個(gè)。如果配置的路徑是classpath:config.properties, 鼠標(biāo)點(diǎn)擊文件。如果顯示”multiple implementations”, 表示有多個(gè)文件,查看其他的文件中是否有需要的配置項(xiàng),沒有的話,很可能就是加載了其他文件的配置項(xiàng)。這時(shí),將路徑改為classpath*:config.properties即可。

查看日志,發(fā)現(xiàn):

[2017-01-05 16:45:02 INFO ] [main] (org.springframework.context.support.PropertySourcesPlaceholderConfigurer:?) - Loading properties file from URL [jar:file:/home/admin/creative-task/lib/xxxx-common-1.5.7.jar!/config.properties][2017-01-05 16:45:02 INFO ] [main] (org.springframework.context.support.PropertySourcesPlaceholderConfigurer:?) - Loading properties file from URL 下載地址

加載了兩個(gè)config.properties文件。

3.關(guān)于診斷:

1)首先確認(rèn)是否正確加載了配置文件。查看日志:

正常日志如下:

[2017-01-05 16:45:02 INFO ] [main] (org.springframework.context.support.PropertySourcesPlaceholderConfigurer:?) - Loading properties file from URL 下載地址

 異常日志如下:

[2017-01-05 16:39:39 ERROR] [main] (Main:22) - Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [config.properties] cannot be opened because it does not existorg.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.io.FileNotFoundException: class path resource [config.properties] cannot be opened because it does not exist

如果文件沒有加載,則查看路徑是否匹配等。

2)如果文件加載ok,查看配置屬性是否正確加載。

查看tomcat啟動(dòng)的debug日志:

正常日志如下:

[2017-01-05 16:45:04 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) - Searching for key 'adx.id' in [environmentProperties][2017-01-05 16:45:04 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) - Searching for key 'adx.id' in [systemProperties][2017-01-05 16:45:04 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) - Searching for key 'adx.id' in [systemEnvironment][2017-01-05 16:45:04 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) - Could not find key 'adx.id' in any property source. Returning [null][2017-01-05 16:45:04 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) - Searching for key 'adx.id' in [localProperties][2017-01-05 16:45:04 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) - Found key 'adx.id' in [localProperties] with type [String] and value '1'

異常日志如下:

[2017-01-05 16:34:01 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) - Searching for key 'adx.id' in [environmentProperties][2017-01-05 16:34:01 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) - Searching for key 'adx.id' in [systemProperties][2017-01-05 16:34:01 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) - Searching for key 'adx.id' in [systemEnvironment][2017-01-05 16:34:01 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) - Could not find key 'adx.id' in any property source. Returning [null][2017-01-05 16:34:01 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) - Searching for key 'adx.id' in [localProperties][2017-01-05 16:34:01 DEBUG] [main] (org.springframework.core.env.PropertySourcesPropertyResolver:?) - Could not find key 'adx.id' in any property source. Returning [null]

上述內(nèi)容就是如何解決spring無法讀取properties文件數(shù)據(jù)問題,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。


分享題目:如何解決spring無法讀取properties文件數(shù)據(jù)問題
文章位置:http://m.jcarcd.cn/article/pepesj.html
主站蜘蛛池模板: 91视频福利影院 | 国产一区二区免费 | 91精品一区 | 九九99九 | 欧美一级影院 | 日韩尤物精品综合网 | 亚洲无码午间福利小电影 | 国产美女精品在线 | 国产无人区一码二码 | 国产午夜福利电影h | 成人精品第一区国产 | 国产精品区一区二 | 国产精品夫妻在线 | 韩国a级特黄特 | 成人免费电影 | 国产人成精品综 | 日本在线看片网站 | 国产高清日本综合 | 97日日| 精品电影日韩亚洲 | 欧洲在线观看 | 欧美另类激情 | 蜜桃视频在线观看 | 国产性爱网 | 精品真实国 | 国产精品一卡 | 乱伦免费影视亚洲 | 国产老熟女狂 | 精品国产自| 91九色熟女| 国产在线日韩欧美 | 国产丰满老熟 | www精品视频| 乱理伦片免费观看 | 91精品国产手机在 | 9久热草极品 | 欧美日韩高清有码 | 碰免费公开视频97 | 午夜福利导航免费 | 国产福利一区二 | 青青国产精品 |