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的更多相关文章

  1. Spring3系列6 - Spring 表达式语言(Spring EL)

    Spring3系列6-Spring 表达式语言(Spring EL) 本篇讲述了Spring Expression Language —— 即Spring3中功能丰富强大的表达式语言,简称SpEL.S ...

  2. Test Spring el with ExpressionParser

    Spring expression language (SpEL) supports many functionality, and you can test those expression fea ...

  3. Spring EL regular expression example

    Spring EL supports regular expression using a simple keyword "matches", which is really aw ...

  4. 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 ...

  5. Spring EL ternary operator (if-then-else) example

    Spring EL supports ternary operator , perform "if then else" conditional checking. For exa ...

  6. Spring EL Operators example

    Spring EL supports most of the standard mathematical, logical or relational operators. For example, ...

  7. Spring EL method invocation example

    In Spring EL, you can reference a bean, and nested properties using a 'dot (.)' symbol. For example, ...

  8. Spring EL hello world example

    The Spring EL is similar with OGNL and JSF EL, and evaluated or executed during the bean creation ti ...

  9. Spring Boot实战笔记(二)-- Spring常用配置(Scope、Spring EL和资源调用)

    一.Bean的Scope Scope描述的是Spring容器如何新建Bean实例的.Spring的Scope有以下几种,通过@Scope注解来实现. (1)Singleton:一个Spring容器中只 ...

  10. Spring 在 xml配置文件 或 annotation 注解中 运用Spring EL表达式

    Spring  EL 一:在Spring xml 配置文件中运用   Spring EL Spring EL 采用 #{Sp Expression  Language} 即 #{spring表达式} ...

随机推荐

  1. 点击图片img提交form表单

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/stri ...

  2. javascript常用的操作

    1.concat()  连接两个或更多的数组,并返回一个新的数组.注意:该方法不会改变原数组 var arry1=["李四",“王二”]:  var arry2=['赵柳',“李旺 ...

  3. python if 和 else

    money = input("请输入你在学校有多少钱?")if int(money) > 5000: print("这个月可以潇洒潇洒了,每天可以出去吃大餐了.&q ...

  4. ORACLE——存储过程

    存储过程procedure 被内容来自<oracle从入门到精通——明日科技>一书 存储过程是一种命名的PL/SQL程序快,存储过程被保存在数据库中,它不可以被SQL语句直接执行或调用,只 ...

  5. select2 api参数中文文档

    select2 api参数的文档   具体参数可以参考一下: 参数 类型 描述 Width 字符串 控制 宽度 样式属性的Select2容器div minimumInputLength int 最小数 ...

  6. hive sql执行的job在map时报java.lang.OutOfMemoryError的错误

    较为详细且重要的一段报错信息是org.apache.hadoop.mapred.YarnChild: Error running child : java.lang.OutOfMemoryError: ...

  7. Linux文件检索

    title: Linux文件检索 date: 2017-12-11 19:03:01 tags: linux categories: linux whereis 只要执行 whereis ls 就可以 ...

  8. Linux Shell自动交互/人机交互的三种方法

    如果你要学习linux,你可能会遇到Linux Shell自动交互问题,这里将介绍Linux Shell自动交互的解决方法,在这里拿出来和大家分享一下. 一.背景 shell脚本在处理自动循环或大的任 ...

  9. WebForm内置对象:Application和ViewState、Repeater的Command用法

    一.内置对象 1.Application 存贮在服务器端,占用服务器内存生命周期:永久 所有人访问的都是这一个对象 传值:传的是object类型可以传对象. string s =TextBox1.Te ...

  10. python 构造一个可以返回多个值的函数

    为了能返回多个值,函数直接return 一个元组就行了 看上去返回了多个值,实际上是先创建了一个元组然后返回的.这个语法看上去比较奇怪,实际上我们使用的是逗号来生成一个元组,而不是用括号 >&g ...