获取一个配置:

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中获取一个或全部配置的更多相关文章

  1. Spring工具类 非spring管理环境中获取bean及环境配置

    SpringUtils.java import org.springframework.beans.BeansException; import org.springframework.beans.f ...

  2. spring mvc controller中获取request head内容

    spring mvc controller中获取request head内容: @RequestMapping("/{mlid}/{ptn}/{name}") public Str ...

  3. spring注解开发中常用注解以及简单配置

    一.spring注解开发中常用注解以及简单配置 1.为什么要用注解开发:spring的核心是Ioc容器和Aop,对于传统的Ioc编程来说我们需要在spring的配置文件中邪大量的bean来向sprin ...

  4. 在 WPF 中获取一个依赖对象的所有依赖项属性

    原文:在 WPF 中获取一个依赖对象的所有依赖项属性 本文介绍如何在 WPF 中获取一个依赖对象的所有依赖项属性. 本文内容 通过 WPF 标记获取 通过设计器专用方法获取 通过 WPF 标记获取 p ...

  5. 在过滤器中获取在web.xml配置的初始化参数

    在过滤器中获取在web.xml配置的初始化参数   例如 <filter> <filter-name>cross-origin</filter-name> < ...

  6. Spring在代码中获取bean的几种方式

    方法一:在初始化时保存ApplicationContext对象 方法二:通过Spring提供的utils类获取ApplicationContext对象 方法三:继承自抽象类ApplicationObj ...

  7. Spring在代码中获取bean的几种方式(转:http://www.dexcoder.com/selfly/article/326)

    方法一:在初始化时保存ApplicationContext对象 方法二:通过Spring提供的utils类获取ApplicationContext对象 方法三:继承自抽象类ApplicationObj ...

  8. Spring在代码中获取properties文件属性

    这里介绍两种在代码中获取properties文件属性的方法. 使用@Value注解获取properties文件属性: 1.因为在下面要用到Spring的<util />配置,所以,首先要在 ...

  9. Spring在代码中获取bean的几种方式(转)

    获取spring中bean的方式总结: 方法一:在初始化时保存ApplicationContext对象 ApplicationContext ac = new FileSystemXmlApplica ...

随机推荐

  1. smartctl----硬盘状态监控

    smartmontools介绍 smartmontools是一款开源的磁盘控制,监视工具,可以运行在Linux,Unix,BSD,Solaris,Mac OS,OS/2,Cygwin和Windows上 ...

  2. 关于java发送email

    转载:https://blog.csdn.net/qq_32371887/article/details/72821291 1:使用JavaMail发送邮件 // 1.创建一个程序与邮件服务器会话对象 ...

  3. hdu 3177 Crixalis&#39;s Equipment

    Crixalis's Equipment Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  4. Android Camera解析(上) 调用系统相机拍摄照片

    开发中我们常须要通过相机获取照片(拍照上传等).一般通过调用系统提供的相机应用就可以满足需求:有一些复杂需求还须要我们自己定义相机相关属性,下篇我们会涉及到. 首先我们来研究怎样简单调用系统相机应用来 ...

  5. centos下yum安装lamp和lnmp轻松搞定

    centos下yum安装lamp和lnmp轻松搞定.究竟多轻松你看就知道了.妈妈再也不操心不会装lamp了. 非常辛苦整理的安装方法,会持续更新下去.凡无法安装的在评论里贴出问题来,会尽快解决.共同维 ...

  6. HDU 1874 畅通project续 (最短路径)

    畅通project续 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in query at index 189......

    Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in query ...

  8. DB-MySQL:MySQL 处理重复数据

    ylbtech-DB-MySQL:MySQL 处理重复数据 1.返回顶部 1. MySQL 处理重复数据 有些 MySQL 数据表中可能存在重复的记录,有些情况我们允许重复数据的存在,但有时候我们也需 ...

  9. 杂项-建模:BIM

    ylbtech-杂项-建模:BIM 建筑信息模型是建筑学.工程学及土木工程的新工具.建筑信息模型或建筑资讯模型一词由Autodesk所创的.它是来形容那些以三维图形为主.物件导向.建筑学有关的电脑辅助 ...

  10. 使用Chrome插件Postman进行简单的Get/Post测试

    转自:https://blog.csdn.net/dearmorning/article/details/56854236 Postman插件: 一种网页调试与发送网页http请求的chrome插件, ...