spring El
package com.wisely.heighlight_spring4.ch2.el; import java.io.IOException; import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource; @Configuration
@ComponentScan("com.wisely.heighlight_spring4.ch2.el")
@PropertySource("classpath:com/wisely/heighlight_spring4/ch2/el/test.properties") //加载属性资源文件
public class ElConfig {
@Value("I love you!") //普通的字符串
private String normal; @Value("#{systemProperties['os.name']}") //系统属性
private String osName; @Value("#{ T(java.lang.Math).random() * 100.0 }") //表达式结果
private double randomNumber; @Value("#{demoService.another}") //其他Bean属性
private String fromAnother; @Value("classpath:com/wisely/heighlight_spring4/ch2/el/test.txt") //文件资源
private Resource testFile; @Value("http://www.baidu.com") //网址资源
private Resource testUrl; @Value("${book.name}") //配置文件
private String bookName; @Autowired
private Environment environment; @Bean
public static PropertySourcesPlaceholderConfigurer propertyConfigure() {
return new PropertySourcesPlaceholderConfigurer();
} public void outputResource() {
try {
System.out.println("normal:"+normal);
System.out.println("osName:"+osName);
System.out.println("randomNumber:"+randomNumber);
System.out.println("fromAnother:"+fromAnother); System.out.println("testFile:"+IOUtils.toString(testFile.getInputStream()));
System.out.println("testUrl:"+IOUtils.toString(testUrl.getInputStream()));
System.out.println("bookName:"+bookName);
System.out.println("environment:"+environment.getProperty("book.author"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
package com.wisely.heighlight_spring4.ch2.el; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; @Service
public class DemoService {
@Value("其它类的属性")
private String another; //注入普通的字符串 public String getAnother() {
return another;
} public void setAnother(String another) {
this.another = another;
} }

spring El的更多相关文章
- Spring3系列6 - Spring 表达式语言(Spring EL)
Spring3系列6-Spring 表达式语言(Spring EL) 本篇讲述了Spring Expression Language —— 即Spring3中功能丰富强大的表达式语言,简称SpEL.S ...
- Test Spring el with ExpressionParser
Spring expression language (SpEL) supports many functionality, and you can test those expression fea ...
- Spring EL regular expression example
Spring EL supports regular expression using a simple keyword "matches", which is really aw ...
- Spring EL Lists, Maps example
In this article, we show you how to use Spring EL to get value from Map and List. Actually, the way ...
- Spring EL ternary operator (if-then-else) example
Spring EL supports ternary operator , perform "if then else" conditional checking. For exa ...
- Spring EL Operators example
Spring EL supports most of the standard mathematical, logical or relational operators. For example, ...
- Spring EL method invocation example
In Spring EL, you can reference a bean, and nested properties using a 'dot (.)' symbol. For example, ...
- Spring EL hello world example
The Spring EL is similar with OGNL and JSF EL, and evaluated or executed during the bean creation ti ...
- Spring Boot实战笔记(二)-- Spring常用配置(Scope、Spring EL和资源调用)
一.Bean的Scope Scope描述的是Spring容器如何新建Bean实例的.Spring的Scope有以下几种,通过@Scope注解来实现. (1)Singleton:一个Spring容器中只 ...
- Spring 在 xml配置文件 或 annotation 注解中 运用Spring EL表达式
Spring EL 一:在Spring xml 配置文件中运用 Spring EL Spring EL 采用 #{Sp Expression Language} 即 #{spring表达式} ...
随机推荐
- nginx基本用法和HTTPS配置
nginx作用讲解:1.反向代理:需要多个程序共享80端口的时候就需要用到反向代理,nginx是反向代理的一种实现方式.2.静态资源管理:一般使用nginx做反向代理的同时,应该把静态资源交由ngin ...
- Spark入门到精通--(第二节)Scala编程详解基础语法
Scala是什么? Scala是以实现scaleable language为初衷设计出来的一门语言.官方中,称它是object-oriented language和functional languag ...
- 17.3-uC/OS-III消息管理(消息队列使用)
多值信号量和和互斥信号量主要用来标志事件是否发生和协调资源的访问.如果要给资源赋予内容进行传递, 信号量就力有所不及了.这时候就需要用到 uC/OS 操作系统的另一个内核机制了,那就是消息队列. 2. ...
- python练习题-day15
1.请利用filter()过滤出1~100中平方根是整数的数,即结果应该是: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100] 2.列表按照其中每一个值的绝对值排序 li ...
- SharePoint开启错误提示
1,打开80下面的Web.config文件2,CallStack="true" 和 <customErrors mode="Off" /> < ...
- Redis入门到高可用(二十)——Redis Cluster
一.呼唤集群 二.数据分布概论 三.哈希分布 1.节点取余 2.一致性哈希 添加一个node5节点时,只影响n1和n2之间的数据 3.虚拟槽分区 四.基本架构 五.redis clust ...
- Session实现原理分析
http://www.jb51.net/article/77726.htm PHP第一次会话时会有Set-Cookie响应头返回,设置上PHPSESSID cookie Cache-Control: ...
- 爬虫出现Forbidden by robots.txt(转载 https://blog.csdn.net/zzk1995/article/details/51628205)
先说结论,关闭scrapy自带的ROBOTSTXT_OBEY功能,在setting找到这个变量,设置为False即可解决. 使用scrapy爬取淘宝页面的时候,在提交http请求时出现debug信息F ...
- 设计模式综合列表【QQ空间日志转载】
C++设计模式全篇 [QQ空间日志转载]
- 裸奔的bootloader单步调试
2011-03-01 23:25:22 目地:更清晰的了解bootloader的结构及功能.为移植U-boot打基础. 以前只知道大概,今天利用IAR调试工具,看着汇编代码,看着寄存器,看着内存.来单 ...