@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}
2018-08-07
https://mp.csdn.net/postedit
2018-05-16
參考: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') ;就可以取到屬性?
2018-02-02
我也遇到了這樣的問題,暫時(shí)不知道為什么,但是用@PropertySource +?Environment 卻可以正確讀到配置
2018-01-20
我就是這樣的 沒問題啊 可是 @Value("${url}")? 取不到數(shù)據(jù)? 他去的是${url} 這玩意? 跟沒識(shí)別一樣
2018-01-19
classpath:一般是在src下面,比如我的src/com/cl/bean/db.properties
我用注解的時(shí)候就會(huì)classpath:com/cl/bean/db.properties