不用@Value从Spring的ApplicationContext中获取一个或全部配置
获取一个配置:
applicationContext.getEnvironment().resolvePlaceholders("${propertyKey}"); // 方法1
applicationContext.getEnvironment().getProperty("propertyKey"); // 方法2
获取properties配置文件的配置:
ConfigurableEnvironment env = (ConfigurableEnvironment) applicationContext.getEnvironment();
MutablePropertySources propertySources = env.getPropertySources();
Iterator<PropertySource<?>> iterator = propertySources.iterator();
while (iterator.hasNext()) {
PropertySource<?> propertySource = iterator.next();
if (propertySource instanceof PropertiesPropertySource) {
System.out.println(propertySource.getProperty("propertyKey"));
// 用propertySource.getSource() 可以获取全部配置
}
}
正常实现EnvironmentAware, 即可让spring容器自动注入Environment
不用@Value从Spring的ApplicationContext中获取一个或全部配置的更多相关文章
- Spring工具类 非spring管理环境中获取bean及环境配置
SpringUtils.java import org.springframework.beans.BeansException; import org.springframework.beans.f ...
- spring mvc controller中获取request head内容
spring mvc controller中获取request head内容: @RequestMapping("/{mlid}/{ptn}/{name}") public Str ...
- spring注解开发中常用注解以及简单配置
一.spring注解开发中常用注解以及简单配置 1.为什么要用注解开发:spring的核心是Ioc容器和Aop,对于传统的Ioc编程来说我们需要在spring的配置文件中邪大量的bean来向sprin ...
- 在 WPF 中获取一个依赖对象的所有依赖项属性
原文:在 WPF 中获取一个依赖对象的所有依赖项属性 本文介绍如何在 WPF 中获取一个依赖对象的所有依赖项属性. 本文内容 通过 WPF 标记获取 通过设计器专用方法获取 通过 WPF 标记获取 p ...
- 在过滤器中获取在web.xml配置的初始化参数
在过滤器中获取在web.xml配置的初始化参数 例如 <filter> <filter-name>cross-origin</filter-name> < ...
- Spring在代码中获取bean的几种方式
方法一:在初始化时保存ApplicationContext对象 方法二:通过Spring提供的utils类获取ApplicationContext对象 方法三:继承自抽象类ApplicationObj ...
- Spring在代码中获取bean的几种方式(转:http://www.dexcoder.com/selfly/article/326)
方法一:在初始化时保存ApplicationContext对象 方法二:通过Spring提供的utils类获取ApplicationContext对象 方法三:继承自抽象类ApplicationObj ...
- Spring在代码中获取properties文件属性
这里介绍两种在代码中获取properties文件属性的方法. 使用@Value注解获取properties文件属性: 1.因为在下面要用到Spring的<util />配置,所以,首先要在 ...
- Spring在代码中获取bean的几种方式(转)
获取spring中bean的方式总结: 方法一:在初始化时保存ApplicationContext对象 ApplicationContext ac = new FileSystemXmlApplica ...
随机推荐
- snmp--CentOS安装Net-SNMP小计
http://blog.csdn.net/tmpbook/article/details/39620549
- C#中的全局程序集缓存定义
安装有公共语言运行时的每台计算机都具有称为全局程序集缓存的计算机范围内的代码缓存.全局程序集缓存中存储了专门指定给由计算机中若干应用程序共享的程序集. 应当仅在需要时才将程序集安装到全局程序集缓存中以 ...
- spring的bean注入扫瞄方法和mybatis的dao bean注入扫描方法
spring的bean注入扫面方法:@ComponentScan(basePackages = "com.pingan.property.icore.pap.*")mybatis的 ...
- iOS富文本(一)属性化字符串
概述 iOS一些复杂的文本布局一般都是由底层的Core Text来实现的,直到iOS7苹果发布了Text Kit框架,Text Kit能够很简单实现一些复杂的文本样式以及布局,而Text Kit富文本 ...
- jenkins启动失败
一:http://localhost:8080已经可以进了 二:修改端口 只是因为8080端口已经有程序占用了,需要修改端口号,但是在jenkins.xml文件中修改端口号,并不起作用. 解决方法是: ...
- php匿名函数和可变参数函数
php匿名函数和可变参数函数 简介 直接上代码了: <?php $test1 = function($value) { echo $value; }; $test1('HelloWorld'); ...
- zzulioj--1769--去师院的旅程:能怎么走(三)(0.0)
1796: 去师院的旅程:能怎么走(三) Time Limit: 1 Sec Memory Limit: 128 MB Submit: 404 Solved: 200 SubmitStatusWe ...
- Memcache使用场景
session //php文件中 ini_set("session.save_handler", "memcache"); ini_set("sess ...
- FluentAPI关系映射配置
都有哪几种关系? 1vs多,多vs多 1. 概念or关系映射相关方法: 1) 基本套路:this.Has***(o=>o.AAA).With***() 当前这个表和AAA属性的表关系是Has定义 ...
- ABBYY FineReader 双十二特惠活动正在进行中...
转眼间11月已悄然飘过,有些童鞋还没缓过双十一的劲,势必将剁手进行到底.只为当时没有鼓足勇气.狠下心来而悔恨其中.别担心,双十二你准备好了么,ABBYY FineReader 系列产品低价让你继续嗨到 ...