首页 > 编程语言 > 详细

SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-009-用SPEL给bean运行时注入依赖值

时间:2016-03-03 13:13:54      阅读:268      评论:0      收藏:0      [点我收藏+]

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:

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‘]}" />

 

SPRING IN ACTION 第4版笔记-第三章ADVANCING WIRING-009-用SPEL给bean运行时注入依赖值

原文:http://www.cnblogs.com/shamgod/p/5238088.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!