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表达式} ...
随机推荐
- 树莓派3 之 USB摄像头安装和使用
需求 如果你想在树莓上拍照或者录影,你可以安装树莓派的摄像头(有点贵).如果你不想要为摄像头模块花费额外的金钱,那有另外一个方法,就是你常见的USB 摄像头.你可能已经在PC上安装过了.我买的如图的这 ...
- 图->连通性->关节点和重连通分量
文字描述 相关定义:假若在删去顶点v以及和v相关联的各边之后,将图的一个连通分量分割成两个或两个以上的连通分量,则称顶点v为该图的一个关节点.一个没有关节点的连通图称为重连通图. 在重连通图上,任意一 ...
- python练习题-day14
一.选择题 1. python不支持的数据类型有:A. charB. intC. floatD. list ans:A 2.x = ‘foo’y = 2print(x + y) A. fooB. fo ...
- PHP自定义curl请求
function http_post($url,$param,$post_file=false,$headers=[]){ $oCurl = curl_init(); if(stripos($url, ...
- nginx cookie 丢失问题
- CentOS 7 keepalived+LVS
LVS架构中 , 不管是NAT模式还是DR模式 , 当后端的RS宕机了 , 调度器还是会把请求转发到宕掉的RS上 , 然而keepalived可以解决该问题 , 它不仅仅有高可用的功能 , 还有负载均 ...
- m2e-wtp的作用
描述 Maven3下的项目结构,target目录下会有一个m2e-wtp文件夹,删除掉会自动生成,有什么作用呢? wtp解释 WTP:Web Tools Project Maven集成WTP The ...
- SpringMvc HandlerMappings 何时初始化?
SpringMvc 的转发控制器 DispatcherServlet 执行 initStrategies(),在什么时候初始化 HandlerMappings ? 在容器 AbstractApplic ...
- Python在金融量开源项目列表
Python也已经在金融量化投资领域占据了重要位置,开源项目列表:
- 4A Watermelon
A. Watermelon time limit per test 1 second memory limit per test 64 megabytes input standard input o ...