首页 > 编程语言 > 详细

spring in action小结3 运行时值注入

时间:2017-06-18 19:49:22      阅读:244      评论:0      收藏:0      [点我收藏+]

装配属性的方法1)使用Environment 相关方法检索。2)解析属性占位符 3) spring表达式语言

1. Environment常用方法

String getProperty(String key);
String getProperty(String key, String defaultValue);
<T> T getProperty(String key, Class<T> targetType);
<T> T getProperty(String key, Class<T> targetType, T defaultValue);

 

2. 占位符使用方法在配置文件中${ ... } 如果是扫描方式或者自动装配使用@Value注解

如果要使用占位符,需要配置 PropertySourcesPlaceholderConfigurer 

@Bean
    public PropertySourcesPlaceholderConfigurer placeholderConfigurer(){
        return new PropertySourcesPlaceholderConfigurer();
    }

 

spring in action小结3 运行时值注入

原文:http://www.cnblogs.com/zhaopengcheng/p/7045028.html

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