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-proxy 简介

    # 背景 今天同事分享的主题就是mysql-proxy,于是下来自己了解下,不求精通,只求知道这个玩意 # 简介 mysql-proxy是mysql官方提供的mysql中间件服务,上游可接入若干个my ...

  2. 关于mysql中like查询是否通过索引的测试

    测试mysql的like语句是否通过索引时得到结果如下: 图片1: 图片2: 图片3: 通过上述3组图片我想大家很容易愤青我使用的'%8888888%','%8888888'和'8888888%'3中 ...

  3. 16.1-uC/OS-III同步 (任务内建信号量)

    1.经常通过发送信号量实现同步.每个任务都有内建的信号量,通过任务内建的信号量不仅可以简化信号量通信的代码而且更加有效. 与任务内建的信号量相关的函数都是以 OSTaskSem???()为前缀的.相关 ...

  4. ASP.NET C# 如何在程序中控制IIS服务或应用程序池重启?

    停止IIS服务ServiceController sc = new ServiceController("iisadmin");if(sc.Status==ServiceContr ...

  5. UDAF(用户自定义聚合函数)求众数

    除了逐行处理数据的udf,还有比较常见的就是聚合多行处理udaf,自定义聚合函数.类比rdd编程就是map和reduce算子的区别. 自定义UDAF,需要extends org.apache.spar ...

  6. python list的函数

    1. list.append(obj) 在列表末尾添加新的对象 2. list.count(obj) 统计某个元素在列表中出现的次数 3. list.extend(seq) 在列表末尾一次性追加另一个 ...

  7. iOS UI基础-21 WKWebView

    WKWebView,直接显示网页,需要引入第三方类:https://github.com/marcuswestin/WebViewJavascriptBridge 加上进度条代码,很完美使用 webV ...

  8. DOM_xss预备知识

    http://xuelinf.github.io/2016/05/18/%E7%BC%96%E7%A0%81%E4%B8%8E%E8%A7%A3%E7%A0%81-%E6%B5%8F%E8%A7%88 ...

  9. pascal中的xor,shr,shl,Int(),ArcTan(),copy,delete,pos和leftstr,RightStr等详解

    数学函数:Inc(i)使I:=I+1;Inc(I,b)使I:=I+b;Abs(x)求x的绝对值例:abs(-3)=3Chr(x)求编号x对应的字符. 例:Chr(65)=’A’chr(97)=’a’c ...

  10. The All-purpose Zero (最长公共子序列)

    题意:求最长公共子序列,但是有个辅助条件,那就是如果那个值为0,那么他可以更换为任意值. 思路:假设现在只剩下没有0的序列是不是就很好求了?那么我们的想法就是看有没有办法将0往最左端或者最有端移动,显 ...