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. MySQL常用运算符:算术运算符、比较运算符、逻辑运算符

    (一)  算术运算符 注意: 在除法运算和模运算中,如果除数为0,将是非法除数,返回结果为NULL. div运算符主要是求两个数相除的商 (二)  比较运算符:比较运算符的运算结果为1(条件为真),0 ...

  2. [redis] redis

    redis是什么? wiki redis官方介绍:introduction to redis 安装: install 拉到最下面的install小节 wget http://download.redi ...

  3. Python的命令模式和交互模式

    Python的命令行模式和交互模式 请注意区分命令行模式和Python交互模式. 在命令行模式下,可以执行python进入Python交互式环境,也可以执行python first.py运行一个.py ...

  4. python摸爬滚打之day20--多继承,MRO和C3算法

    1.新式类和经典类 在python2.2之前, 基类如果不写(), 则表示为经典类; 在python2.2之后, 经典类不复存在, 只存在新式类. 如果基类谁都不继承的话, 则默认继承object. ...

  5. C++提供的四种新式转换--const_cast dynamic_cast reinterpret_cast static_cast

    关于强制类型转换的问题,许多书都讨论过,写的最具体的是C++之父的<C++的设计和演化>. 最好的解决方法就是不要使用C风格的强制类型转换,而是使用标准C++的类型转换符:static_c ...

  6. Python sys.argv[]用法

    sys.argv,其实就是一个list,它是sys模块下的一个全局变量,第一个元素是模块名.后面是依次传入的参数. 比如可以这样传入 pyton temp.py a b c d,一共传入a.b.c.d ...

  7. ZooKeeper是什么

    ZooKeeper概念 相信大家对 ZooKeeper 应该不算陌生,但是你真的了解 ZooKeeper 是什么吗?如果别人/面试官让你讲讲 ZooKeeper 是什么,你能回答到哪个地步呢? 本人曾 ...

  8. Android Studio 添加已经移除的Module

    Android Studio 删除Module时,需要先在Project Structure中点击“-”来移除,此时小手机图标消失,但是这个时候Module并没有在硬盘中删除,只是和这个Project ...

  9. 提交SR的一些小技巧

    在平时的时候,遇到一些问题总会在metalink上提交SR(Service Request,SR,过去也叫Technical Assistance Request,TAR ),我们提交sr的时候,总是 ...

  10. scp传输文件,自动填充密码

    一个偷懒的小shell, #!/usr/bin/expect #******************************************************************** ...