---
title: "hibernate的Configuration对象的configure()方法的作用"
author: "孙健坤"
date: "2009-11-15T15:56:12Z"
tags: []
slug: "hibernate-configuration-configure"
draft: false
lastmod: "2009-11-15T15:56:12Z"
id: 517586
url: "https://sunjin.iteye.com/blog/517586"
---

做hibernate的小练习，对configuration的configure()方法很好奇，为啥创建的对象还要执行这个方法呢。

Configuration cfg = **new** Configuration().configure();

原来configure()方法默认会在classpath下面寻找hibernate.cfg.xml文件，如果没有找到该文件，系统会打印如下信息并抛出HibernateException异常。

其实不使用configure()方法也可以Configuration cfg = **new** Configuration();这时hibernate会在classpath下面寻找hibernate.properties文件，如果没有找到该文件，系统会打印如下信息并抛出HibernateException异常。