課程
/后端開發(fā)
/Java
/Spring入門篇
這里用來創(chuàng)建容器的xml文件即測試時super()里填的xml文件是怎么配置的
2017-08-22
源自:Spring入門篇 4-6
正在回答
參考:https://my.oschina.net/u/2326864/blog/1786955
1。@PropertySource+@Value
要想使用@Value 用${}占位符注入屬性,這個bean是必須的(PropertySourcesPlaceholderConfigurer), ? ?//這個就是占位bean?
如果不用的話,
Value("${url}")
private String url;
@Value("value") 里面的value就是String url的值
加上這段代碼,會識別${}占位符:
@Bean
? ? public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
? ? ? ?return new PropertySourcesPlaceholderConfigurer();
? ? }
2.@PropertySource+@Value+@Envirment
?另一種方式是不用value直接用Envirment變量直接getProperty('key') ?
@Autowired
private?Envirment envirment;
使用envirment.getProperty('key') ;就可以取到屬性?
這個xml文件就是spring的配置文件,遵循spring的xml配置語法
那一年故鄉(xiāng) 提問者
舉報
為您帶來IOC和AOP的基本概念及用法,為后續(xù)高級課程學(xué)習(xí)打下基礎(chǔ)
2 回答關(guān)于beans配置的問題
3 回答關(guān)于spring配置文件提示信息
1 回答不知道是不是xml文件配置錯誤問題
2 回答關(guān)于用list裝配的問題
1 回答配置文件該如何創(chuàng)建?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2018-05-16
參考:https://my.oschina.net/u/2326864/blog/1786955
1。@PropertySource+@Value
要想使用@Value 用${}占位符注入屬性,這個bean是必須的(PropertySourcesPlaceholderConfigurer), ? ?//這個就是占位bean?
如果不用的話,
Value("${url}")
private String url;
@Value("value") 里面的value就是String url的值
加上這段代碼,會識別${}占位符:
@Bean
? ? public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
? ? ? ?return new PropertySourcesPlaceholderConfigurer();
? ? }
2.@PropertySource+@Value+@Envirment
?另一種方式是不用value直接用Envirment變量直接getProperty('key') ?
@Autowired
private?Envirment envirment;
使用envirment.getProperty('key') ;就可以取到屬性?
2017-08-23
這個xml文件就是spring的配置文件,遵循spring的xml配置語法