从配置文件(properties)中读取配置项

配置文件:(src/main/resources/config.properties)

hsf.container.path=D:/usr/share/hsf
id=7628bd2634914d2ebeff0d6cd19b642c

//调用配置文件

public class Timing {


    private Properties propertie = new Properties();
    private IReviewService reviewService = null;
    
    public static void main(String args[]) throws Exception{
        Timing timing = new Timing();
        timing.init();
        timing.run();
        System.exit(0);
    }
    
    public void init() throws Exception {
        String configPath = "/config.properties";//配置文件的加载位置
        try {
            InputStream in = this.getClass().getResourceAsStream(configPath);
            propertie.load(in);
            String path = propertie.getProperty("hsf.container.path");
            HSFContainerDelegator.start(path);
            Thread.sleep(5000); // 保障HSF容器完整启动
            ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(
            "demo.application.xml");
            reviewService = (IReviewService)appContext.getBean("reviewService");
        } catch (Exception e) {
            System.out.println("[Error init!]" + "get config exception"+e.getMessage());
            e.printStackTrace();
        }
    }
    
    public void run(){
        String id = propertie.getProperty("id");
        QueryById qid = new QueryById(id);
        Review reivew = reviewService.load(qid);
        System.out.println("This is log demo");
        System.out.println("Load review by id from propertyies is null?"+(null == reivew));
    }
    
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值