Spring 中注入 properties 中的值
原创
©著作权归作者所有:来自51CTO博客作者tonycody的原创作品,请联系作者获取转载授权,否则将追究法律责任
HTML Code
1 2 3 4 5 6 7 8 9 10
|
| <bean id="ckcPlaceholderProperties" class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <property name="locations"> <list> <value>classpath:default.properties</value> </list> </property> <property name="order" value="2"></property> <property name="ignoreUnresolvablePlaceholders" value="true" /> </bean> <bean id="pathConfig" class="com.movitech.erms.business.configuration.PathConfig"/> |
HTML Code
1 2 3 4
|
| # default.properties file content local.p_w_upload.path=1 p_w_upload.resume.path=2 interview.p_w_upload.path=D:\My Document |
Java Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
| /** * PathConfig 注入的类文件 * * @author Tony.Wang * @time 2014/4/28 0028 17:31 */ public class PathConfig {
@Value("${local.p_w_upload.path}") private String localAttachmentPath;
@Value("${p_w_upload.resume.path}") private String p_w_uploadResumePath;
@Value("${interview.p_w_upload.path}") private String interviewAttachmentPath;
public String getLocalAttachmentPath() { return localAttachmentPath; }
public String getInterviewAttachmentPath() { return interviewAttachmentPath; }
public String getAttachmentResumePath() { return p_w_uploadResumePath; } } |
Java Code
1 2
|
| @Resource private PathConfig pathConfig; |