SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-009-用SPEL给bean运行时注入依赖值
2016-03-03 12:11
537 查看
1.When injecting properties and constructor arguments on beans that are created
via component-scanning, you can use the @Value annotation, much as you saw earlier
with property placeholders. Rather than use a placeholder expression, however, you
use a S p EL expression. For example, here’s what the BlankDisc constructor might
look like, drawing the album title and artist from system properties:
2.In XML configuration, you can pass in the S p EL expression to the value attribute of
<property> or <constructor-arg> , or as the value given to a p-namespace or c-
namespace entry. For example, here’s the XML declaration of the BlankDisc bean
that has its constructor arguments set from a S p EL expression:
via component-scanning, you can use the @Value annotation, much as you saw earlier
with property placeholders. Rather than use a placeholder expression, however, you
use a S p EL expression. For example, here’s what the BlankDisc constructor might
look like, drawing the album title and artist from system properties:
public BlankDisc( @Value("#{systemProperties['disc.title']}") String title, @Value("#{systemProperties['disc.artist']}") String artist) { this.title = title; this.artist = artist; }
2.In XML configuration, you can pass in the S p EL expression to the value attribute of
<property> or <constructor-arg> , or as the value given to a p-namespace or c-
namespace entry. For example, here’s the XML declaration of the BlankDisc bean
that has its constructor arguments set from a S p EL expression:
<bean id="sgtPeppers" class="soundsystem.BlankDisc" c:_title="#{systemProperties['disc.title']}" c:_artist="#{systemProperties['disc.artist']}" />
相关文章推荐
- 『java.util』 AbstractCollection
- SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-008-SpEL介绍
- Java IO读写
- eclipse控制台输出重定向到文件
- java xml解析工具
- Java 对象属性的遍历
- 【JAVA】别特注意,POI中getLastRowNum() 和getLastCellNum()的区别
- java中&& 、|| 操作的捷径
- Java WebService 简单实例
- Java多线程之concurrent包(二)——线程安全集合
- Java排序算法总结之(四)——归并排序
- 【leetcode】【90】Subsets II
- MapReduce分布式缓存程序,无法在Windows下的Eclipse中执行问题解决
- 编写类与子类时的偷懒~~
- ValueStack、OGNL和Struts2标签
- Leetcode:263. Ugly Number(JAVA)
- eclipse调试java程序的九个技巧
- Java中静态成员
- Java中的静态内部类与非静态内部类的区别
- java加时间