配置文件:(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));
}
}