Java obtain the configuration file attributes

Gets the property value profile

example

Target profile jdbc.properties, now you want to call the java class url opcl inside

jdbc.url=jdbc:mysql://localhost:3306/eoms?useUnicode=true&characterEncoding=utf-8
jdbc.username=root
jdbc.password=123
jdbc.initialSize=5
jdbc.maxActive=30
jdbc.minIdle=5
jdbc.maxWait=60000

#opcl接口
opcl.url=http://localhost:8080/opcl

#MDMjiekou  url
MDM.url=http://20.65.3.136:4880/hermes

Java implementation

    /* 
    * <p>Title: getUrl</p>
    * <p>Description: 该service方法获取配置文件里的url</p>
    * @return
    * @see com.ai.system.service.ZdmmService#getUrl()
    */
    @Override
    public String getUrl() {

        // 获取配置文件
        Properties properties = new Properties();
        InputStream in = ManagerController.class.getResourceAsStream("/conf/configures/jdbc/jdbc.properties");
        try {
            properties.load(in);
        } catch (IOException e1) {
            logger.error("ZdmmServiceImpl类getUrl方法获取opcl配置文件失败");
        }
        return properties.getProperty("opcl.url");
    }

Imported class

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

Guess you like

Origin www.cnblogs.com/yonyong/p/11299001.html