|
protected InputStream getConfigurationInputStream(String resource) throws HibernateException { InputStream stream = Environment.class.getResourceAsStream(resource); } client应该这么写: //hibernate.cfg.xml位于classes目录下(classPath目录) InputStream stream = getConfigurationInputStream("/hibernate.cfg.xml"); 如果资源是.property的配置文件,则可以这么装载 Properties property=new Properties(); property.load(stream); 总起来可以这么写: public Properties getPropFromFile(String filePath){ InputStream stream = Environment.class.getResourceAsStream(resource); Properties property=new Properties(); property.load(stream);
} |
得到配置资源的一般做法--CLASS.getResourceAsStream(String resource)
最新推荐文章于 2022-08-24 11:39:04 发布
本文介绍了一种从类路径中加载配置文件的方法,例如 hibernate.cfg.xml,并演示了如何使用 Java 的 InputStream 和 Properties 类来读取这些配置文件。
914

被折叠的 条评论
为什么被折叠?



