spring @value resource

看个例子:

@Value("rules.xml")
private Resource ruleConfig;

spirng会读取这个配置文件,然后尝试帮你生成Resource对象。

其中,value括号中的参数可以是字符串,也可以用el表达式,形如${}。

注意:classpath放在其中有可能是识别不了的。

el表达式例子:http://stackoverflow.com/questions/7019642/injecting-a-classpath-resource-into-a-spring-3-bean

用classpath也可以的例子:http://stackoverflow.com/questions/7484594/spring-3-0-inject-files-as-resources

el表达式例子2:http://www.mkyong.com/spring3/spring-value-default-value/、

el表达式例子3:http://9leg.com/spring/2015/02/12/spring-propertysource-value-annotations-example.html

猜你喜欢

转载自wandejun1012.iteye.com/blog/2297820