ITeye博客

Hibernate 读取配置文件

villain564 · 2010-09-16 23:20 · hibernate · 企业架构 · Hibernate · thread · Markdown

public static InputStream getResourceAsStream(String resource) {
  String stripped = resource.startsWith("/") ?
    resource.substring(1) : resource;

  InputStream stream = null;
  ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
  if (classLoader!=null) {
   stream = classLoader.getResourceAsStream( stripped );
  }
  if ( stream == null ) {
   stream = Environment.class.getResourceAsStream( resource );
  }
  if ( stream == null ) {
   stream = Environment.class.getClassLoader().getResourceAsStream( stripped );
  }
  if ( stream == null ) {
   throw new HibernateException( resource + " not found" );
  }
  return stream;
 }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。