【发布时间】:2016-06-29 13:31:54
【问题描述】:
是否可以只使用hibernate.properties 文件来配置休眠而没有任何hibernate.cfg.xml 文件?
我已经在 hibernate.properties 文件中定义了所需的属性。
hibernate.dialect=org.hibernate.dialect.MySQLDialect
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost:3306/dev
hibernate.connection.username=root
hibernate.connection.password=
hibernate.connection.pool_size=1
hibernate.show_sql=true
hibernate.format_sql=true
hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider
hibernate.hbm2ddl.auto=update
休眠显示:
Loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=com.mysql.jdbc.Driver, hibernate.cache.provider_class=org.hibernate.cache.NoCacheProvider, hibernate.dialect=org.hibernate.dialect.MySQLDialect, hibernate.format_sql=true, hibernate.connection.username=root, hibernate.hbm2ddl.auto=update, hibernate.connection.url=jdbc:mysql://localhost:3306/dev, hibernate.bytecode.use_reflection_optimizer=false, hibernate.show_sql=true, hibernate.connection.password=****, hibernate.connection.pool_size=1}
但它仍然要求cfg.xml:
Exception in thread "main" org.hibernate.internal.util.config.ConfigurationException: Could not locate cfg.xml resource [hibernate.cfg.xml]
【问题讨论】:
-
有可能。看到这个tutorial。将
hibernate.properties放在应用程序 CLASSPATH 的根目录中
标签: java xml hibernate properties-file