如何通过Spring读取Properties文件
1 在Spring中配置文件中, 配置配置文件的引用
public class SpringContextHolder implements ApplicationContextAware {
private static final Logger logger = Logger.getLogger(SpringContextHolder.class);
private static ApplicationContext ctx=null;
public void setApplicationContext(ApplicationContext context) throws BeansException {
SpringContextHolder.ctx=context;
}
private SpringContextHolder(){
}
public static ApplicationContext getCtx(){
return ctx;
}
public static Object getBean(String name){
return ctx.getBean(name);
}
}
|
加载Spring配置文件时,如果Spring配置文件中所定义的Bean类实现了ApplicationContextAware 接口,那么在加载Spring配置文件时,会自动调用ApplicationContextAware 接口中的 public void setApplicationContext(ApplicationContext context) throws BeansException 方法,设置ApplicationContext对象。 前提必须在Spring配置文件中指定该类 |
Properties properties = (Properties) SpringContextHolder.getBean("settings");
如何通过Spring读取Properties文件的更多相关文章
- Java-马士兵设计模式学习笔记-工厂模式-模拟Spring读取Properties文件
一.目标:读取properties文件,获得类名来生成对象 二.类 1.Movable.java public interface Movable { void run(); } 2.Car.java ...
- spring 读取properties文件--通过注解方式
问题: 需要通过properties读取页面的所需楼盘的名称.为了以后便于修改. 解决: 可以通过spring的 PropertiesFactoryBean 读取properties属性,就不需要自己 ...
- spring读取properties文件
1.方式一 <util:properties id="meta" location="classpath:config/metainfo.properties&qu ...
- spring 框架的xml文件如何读取properties文件数据
spring 框架的xml文件如何读取properties文件数据 第一步:在spring配置文件中 注意:value可以多配置几个properties文件 <bean id="pro ...
- spring使用@Value注解读取.properties文件时出现中文乱码问题的解决
解决办法 在spring中我们常常使用.properties对一些属性进行一个提前配置, spring 在读取*.properties文件时, 默认使用的是asci码, 这时 我们需要对其编码进行转换 ...
- Spring 如何读取properties文件内容
http://hi.baidu.com/alizv/blog/item/d8cb2af4094662dbf3d38539.html 在现实工作中,我们常常需要保存一些系统配置信息,大家一般都会选择配置 ...
- Spring下读取properties文件
由于在spring的xml文件中配置了 <bean id="validator" class="org.springframework.validation.bea ...
- 五种方式让你在java中读取properties文件内容不再是难题
一.背景 最近,在项目开发的过程中,遇到需要在properties文件中定义一些自定义的变量,以供java程序动态的读取,修改变量,不再需要修改代码的问题.就借此机会把Spring+SpringMVC ...
- classpath 及读取 properties 文件
java代码中获取项目的静态文件,如获取 properties 文件内容是必不可少的. Spring 下只需要通过 @Value 获取配置文件值 <!-- 资源文件--> <util ...
随机推荐
- solr分组排序实现group by功能
http://wiki.apache.org/solr/FieldCollapsing solr分组排序,实现group by功能,代码待添加!
- Git和Github入门
推文:官方手册,十分详细 推文:git和github快速入门 一.git使用 1.git安装 (1)windows 网站:https://git-scm.com/download/win下载安装即可 ...
- 1 Kafka概念和架构
第一讲:概念.ZK的存储结构.Producer.Consumers流程.Kafka Broker的启动(额外) 从客户端使用角度来讲. 第二讲:从设计原理角度来讲. Kafka属于Apache组织,是 ...
- AAC音频格式详解
关于AAC音频格式基本情况,可参考维基百科http://en.wikipedia.org/wiki/Advanced_Audio_Coding AAC音频格式分析 AAC音频格式有ADIF和ADTS: ...
- Shell记录-Shell脚本基础(三)
if...fi 语句的基本控制语句,它允许Shell有条件作出决定并执行语句. 语法 if [ expression ] then Statement(s) to be executed if exp ...
- 51 nod 1058 N的阶乘的长度
1058 N的阶乘的长度 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 输入N求N的阶乘的10进制表示的长度.例如6! = 720,长度为3. In ...
- jmeter上传图片附件-小插曲
背景 最近,接到新项目的接口测试,发现该接口是需要上传图片,开始折腾了好久没有搞定,最后才发现st和sid,并不是作为请求实体,而是url的一部分,好吧,是我没有仔细 请求参数 { "con ...
- CSS3实战-文字篇
text-shadow的大作用 多颜色阴影效果,用逗号分隔text-shaodow即可. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Tr ...
- 在传统的ADO.NET中使用事务
using (SqlConnection conn = new SqlConnection()) { SqlCommand cmd = conn.CreateCommand(); //启动事务 Sql ...
- Java写的数据库连接池
原文地址: http://lgscofield.iteye.com/blog/1820521 import java.sql.*; import java.util.Enumeration; impo ...