spring基础----EL和资源调用

EL-Spring 支持在xml和注解中使用表达式,经常涉及调用各种资源的情况,主要在注解@Value的参数上使用表达式

1、普通字符

@Value("字符串")

private String arguments;

2、操作系统的属性

@Value("#{systemProperties['os.name']}")

private String OSName;

3、表达式运算结果

@Value("#{T(java.lang.Math).random() * 100.0}")

private double randomNumber;

4、注入其他Bean的属性

@Value("#{demoService.name}")

private String name;

5、注入文件资源

@Value("classpath:com/java/text.txt")

private Resource testFile;

6、注入网址资源

@Value("http://www.baidu.com")

private Resource url;

7、注入配置文件

@Value("${book.name}");  //注意是$ 而不是 #     要用PropertySource注解配置文件的位置。

private String name;

原文地址:https://www.cnblogs.com/lzhirong/p/9246430.html