通过Properties文件配置

package com.phoenix.wistariz.base.consts;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import com.ebiz.framework.util.validate.FormatUtil;

public class EmdConst {

private static Properties prop;
public static String EMD_IP = null;
public static int EMD_PORT = 0;
public static String EMD_APPNAME = null;
public static String EMD_OFFICE = null;
public static String EMD_CUSTOMNO = null;
public static String EMD_VALIDATIONNO = null;

public static String MU_AIR=null;
public static String MU_CHANNEL=null;
public static String MU_OFFICECODE=null;
public static String MU_IATANO=null;

static{
if(null==prop){
initEmdProperties();
}
}

public static void initEmdProperties(){
prop=new Properties();
try {
InputStream inp=EmdConst.class.getResourceAsStream("/emdclient.properties");
prop.load(inp);
inp.close();
} catch (IOException e) {
//如果发生IO异常,返回
return;
}
EmdConst.EMD_IP=prop.getProperty("server.ip");
EmdConst.EMD_PORT=FormatUtil.toInt(prop.getProperty("server.port"));
EmdConst.EMD_APPNAME=prop.getProperty("client.app");
EmdConst.EMD_OFFICE=prop.getProperty("client.office");
EmdConst.EMD_CUSTOMNO=prop.getProperty("client.customno");
EmdConst.EMD_VALIDATIONNO=prop.getProperty("client.validationno");

EmdConst.MU_AIR=prop.getProperty("mu.airline");
EmdConst.MU_CHANNEL=prop.getProperty("mu.channel");
EmdConst.MU_OFFICECODE=prop.getProperty("mu.officeno");
EmdConst.MU_IATANO=prop.getProperty("mu.iatano");
}

}

资源文件Properties:

server.ip=172.25.5.2
server.port=8091
client.app=muairb2cetd1
client.office=sha777
client.customno=0
client.validationno=2

mu.airline=MU
mu.channel=B2C
mu.officeno=SHA777
mu.iatano=08690450

时间: 2024-07-31 01:29:45

通过Properties文件配置的相关文章

通过.properties文件配置参数

通过.properties文件配置参数的好处最重要的就是,如果在维护时这个参数被频繁的修改,只需要在.properties文件里面修改一次即可. 在src文件夹下新建.properties文件,在里面添加变量和值. 那么如何在代码中使用.properties文件的变量呢? private static String wsUrl; static{ InputStream inputStream = SpaceInfoImpl.class.getResourceAsStream("/Constant

SpringBoot中自定义properties文件配置参数并带有输入提示

1. 创建配置类 在项目中创建一个参数映射类如下 @ConfigurationProperties(prefix = "user.info") public class MyProperties { private String name; private Integer age; public String getName() { return name; } public void setName(String name) { this.name= name; } public S

log4cplus库的properties文件配置

使用时需要先获取一个Logger的对象,下面获取Logger对象的内容对应于配置: Logger LogConsole = Logger::getInstance(LOG4CPLUS_TEXT("console")); Logger LogRoot = Logger::getInstance(LOG4CPLUS_TEXT("root")); log4cplus常用配置如下: #配置文件(其它日志级别配置相同): log4cplus.logger.console=TR

log4j.properties文件配置--官方文档

Default Initialization Procedure The log4j library does not make any assumptions about its environment. In particular, there are no default log4j appenders. Under certain well-defined circumstances however, the static inializer of the Logger class wi

oracle的jdbc.properties文件配置

----------Oracle jdbc.driver_class=oracle.jdbc.driver.OracleDriver    //数据库驱动jdbc.connection.url=jdbc:oracle:thin:@localhost:1521:orcl   //数据库地址jdbc.connection.username=//数据库名称jdbc.connection.password=//数据库密码 原文地址:https://www.cnblogs.com/curedfisher/

【Spring源码分析】.properties文件读取及占位符${...}替换源码解析

前言 我们在开发中常遇到一种场景,Bean里面有一些参数是比较固定的,这种时候通常会采用配置的方式,将这些参数配置在.properties文件中,然后在Bean实例化的时候通过Spring将这些.properties文件中配置的参数使用占位符"${}"替换的方式读入并设置到Bean的相应参数中. 这种做法最典型的就是JDBC的配置,本文就来研究一下.properties文件读取及占位符"${}"替换的源码,首先从代码入手,定义一个DataSource,模拟一下JDB

获取项目中Properties文件

在web项目中读取Properties文件配置: properties文件内容: name=tom password=12345 1.使用 类名.class.getResourceAsStream() private void readPropertiesByClass() { // 根目录是class文件所在目录,如果以 /开头从classpath目录中找db.properties;如果不以/开头从当前类所在的包中找 InputStream inputStream = ReadProperti

log4j.properties详细配置解析

最近在学习Maven,顺便学习了下Spring MVC和Log4j作为后续的知识储备,下面详细记录Log4j的properties文件配置. log4j.properties是Log4j的启动配置文件,用来设置记录器的级别.存放器和布局的,它可接key=value格式的设置或xml格式的设置信息.通过配置,可以创建出Log4J的运行环境. 配置模板 Log4J配置文件的基本格式如下: #配置根Loggerlog4j.rootLogger  = [ Level ] ,  appenderName1

SpringMVC+HibernateValidator,配置在properties文件中的错误信息回显前端页面出现中文乱码

问题: 后台在springMVC中使用hibernate-validator做参数校验的时候(validator具体使用方法见GOOGLE),用properties文件配置了校验失败的错误信息.发现回显给前端页面的时候中文错误信息显示乱码. 封装参数的POJO类 public class UserReqBean { @NotNull(message="{user.name.notnull}") private String userName; } ValErrMsg.propertie