Spring afterPropertiesSet方法读取系统配置文件实例
来源:互联网 发布:知乎 二十年目睹怪现状 编辑:程序博客网 时间:2024/06/18 15:28
package com.common;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class SystemConfig implements InitializingBean {
@Value("${config.properties}")
private String SYSTEM_CONFIG;//系统配置文件名
// 服务查询条件映射
private static Properties sysConfig = null;
/**
* 获取系统配置信息
*
* @param name
* @return
*/
public static String getPropertity(String name) {
return sysConfig.getProperty(name);
}
/**
* 判断系统配置信息中存在
*
* @return
*/
public static boolean isExists(String name) {
return sysConfig.getProperty(name) != null;
}
@Override
public void afterPropertiesSet() throws Exception {
InputStream stream = SystemConfig.class.getClassLoader().getResourceAsStream(SYSTEM_CONFIG);
sysConfig = new Properties();
try {
sysConfig.load(stream);
} catch (IOException e) {
throw new ExceptionInInitializerError("读取系统配置文件失败");
}
}
}
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
@Component
public class SystemConfig implements InitializingBean {
@Value("${config.properties}")
private String SYSTEM_CONFIG;//系统配置文件名
// 服务查询条件映射
private static Properties sysConfig = null;
/**
* 获取系统配置信息
*
* @param name
* @return
*/
public static String getPropertity(String name) {
return sysConfig.getProperty(name);
}
/**
* 判断系统配置信息中存在
*
* @return
*/
public static boolean isExists(String name) {
return sysConfig.getProperty(name) != null;
}
@Override
public void afterPropertiesSet() throws Exception {
InputStream stream = SystemConfig.class.getClassLoader().getResourceAsStream(SYSTEM_CONFIG);
sysConfig = new Properties();
try {
sysConfig.load(stream);
} catch (IOException e) {
throw new ExceptionInInitializerError("读取系统配置文件失败");
}
}
}
阅读全文
0 0
- Spring afterPropertiesSet方法读取系统配置文件实例
- Spring afterPropertiesSet方法
- Spring afterPropertiesSet方法
- Spring InitializingBean的afterPropertiesSet方法
- Spring InitializingBean的afterPropertiesSet方法
- 读取系统配置文件
- java 读取系统配置文件
- InitializingBean afterPropertiesSet方法
- 读取spring配置文件的方法(spring读取资源文件)
- 远程下载文件并读取实例方法
- spring的InitializingBean的 afterPropertiesSet 方法 和 init-method配置的 区别联系
- spring的InitializingBean的 afterPropertiesSet 方法 和 init-method配置的 区别联系
- spring的InitializingBean的 afterPropertiesSet 方法 和 init-method配置的 区别联系
- [模拟Spring]java读取xml文件,并实例化
- 读取Spring bean实例
- Spring的init-method 与afterPropertiesSet
- 用spring的InitializingBean的afterPropertiesSet初始化
- 从源码实现的角度解析spring的InitializingBean的afterPropertiesSet方法和init-method区别和应用
- Springboot的第一个程序
- FZU 2020 组合(组合数 lucas定理模板题)
- 踏入AI前的准备工作 opencv ---20170809
- 怎么查看一个网站是用什么语言编写的?
- 关于input中title
- Spring afterPropertiesSet方法读取系统配置文件实例
- 欢迎使用CSDN-markdown编辑器
- Mybatis学习之路(二)
- mysql 5.7 InnoDB 添加全文索引
- python 算法
- Recycle 实现二级列表
- javaweb中过滤器跟拦截器的区别
- Java中null
- java获取pid和management包