第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

@PropertySource("classpath:/com/etoak/importresource/jdbc.properties")無效

gtrfans 可以不使用@ImportResource("classpath:config.xml"),也不必配置xml文件,直接用@PropertySource("classpath:config.properties")就可以獲取配置文件的數(shù)據(jù)。 spring4以上 我用的4.17 為什么 引入無效 輸出 uri==>${url} user==>${user} name==>${pass}

正在回答

5 回答

https://mp.csdn.net/postedit

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

Bruth_Lee

這篇博客寫到了的哈,主要是注解使用錯(cuò)誤
2018-08-07 回復(fù) 有任何疑惑可以回復(fù)我~

參考:https://my.oschina.net/u/2326864/blog/1786955

1。@PropertySource+@Value

要想使用@Value 用${}占位符注入屬性,這個(gè)bean是必須的(PropertySourcesPlaceholderConfigurer), ? ?//這個(gè)就是占位bean?

如果不用的話,

Value("${url}")

private String url;

@Value("value") 里面的value就是String url的值

加上這段代碼,會(huì)識(shí)別${}占位符:

@Bean

? ? public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {

? ? ? ?return new PropertySourcesPlaceholderConfigurer();

? ? }

2.@PropertySource+@Value+@Envirment

?另一種方式是不用value直接用Envirment變量直接getProperty('key') ?

@Autowired

private?Envirment envirment;

使用envirment.getProperty('key') ;就可以取到屬性?


0 回復(fù) 有任何疑惑可以回復(fù)我~

我也遇到了這樣的問題,暫時(shí)不知道為什么,但是用@PropertySource +?Environment 卻可以正確讀到配置http://img1.sycdn.imooc.com//5a73f674000191e311550174.jpg

0 回復(fù) 有任何疑惑可以回復(fù)我~

我就是這樣的 沒問題啊 可是 @Value("${url}")? 取不到數(shù)據(jù)? 他去的是${url} 這玩意? 跟沒識(shí)別一樣

0 回復(fù) 有任何疑惑可以回復(fù)我~

classpath:一般是在src下面,比如我的src/com/cl/bean/db.properties

我用注解的時(shí)候就會(huì)classpath:com/cl/bean/db.properties

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕村8951117 提問者

我就是這樣的 沒問題啊 可是 @Value("${url}") 取不到數(shù)據(jù) 他去的是${url} 這玩意 跟沒識(shí)別一樣 你給下你的代碼 配置嗎 謝謝
2018-01-20 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Spring入門篇
  • 參與學(xué)習(xí)       268802    人
  • 解答問題       1026    個(gè)

為您帶來IOC和AOP的基本概念及用法,為后續(xù)高級(jí)課程學(xué)習(xí)打下基礎(chǔ)

進(jìn)入課程

@PropertySource("classpath:/com/etoak/importresource/jdbc.properties")無效

我要回答 關(guān)注問題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)