- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Jetty 1.6 上运行的 GWT 应用程序中使用 Hibernate 4.1获得了启动 hib.instance 的下一个代码:
Configuration configuration = new Configuration().configure(ABS_PATH_TO_CONFIG+File.separator+"hibernate.cfg.xml");
ServiceRegistry serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
第一行给我一个错误:
org.hibernate.HibernateException: ...hibernate.cfg.xml not found
at org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:173)
但我在加载 hib.config 之前检查了 hibernate.cfg.xml
可用性:
File conf = new File(ABS_PATH_TO_CONFIG+File.separator+"hibernate.cfg.xml");
System.out.println(conf.canRead());
Sysout 返回真。
查看带有断点的 ConfigHelper.getResourceAsStream
源代码:
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" );
}
我做错了什么(不明白什么)或者这里真的没有 xml 加载器?
最佳答案
这里有几处错误。
首先,这个:
Configuration configuration = new Configuration().configure(ABS_PATH_TO_CONFIG+File.separator+"hibernate.cfg.xml");
不会按照您的想法去做。
您的示例没有检查配置文件的可用性。它正在检查文件是否存在于文件系统中,而不是类路径中。这种差异很重要。
在不了解更多有关如何构建和部署 Web 应用程序或如何组织文件的情况下,除了尝试将“hibernate.cfg.xml”复制到类路径的根目录外,很难给您任何更具体的建议,然后将其传递给 configure() 方法。这应该有效。
所以你的代码应该是:
Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
并且您的 hibernate.cfg.xml 文件应该位于类路径的根目录中。
或者,如果您使用 Maven,只需将它放在“资源”文件夹下,Maven 会为您完成剩下的工作。
关于java - Hibernate 无法读取 hibernate.cfg.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15761912/
我有一个Java项目,正在使用hibernate。这里的事情是我想将hibernate.cfg.xml文件放在“src”文件夹之外,但是当我配置该文件时,它显示FileNotFoundExceptio
我想了解 #[cfg(test)] 和 #[cfg(feature = "test")] 之间的区别,最好通过示例进行演示。 最佳答案 #[cfg(test)] 标记仅当启用 test 配置选项时才编
如果我启动 cppcheck,我会收到以下错误: cppcheckListLib.c(信息)无法加载 std.cfg。您的 Cppcheck 安装已损坏,请重新安装。 Cppcheck 二进制文件是在
我想了解 #[cfg(test)] 和 #[cfg(feature = "test")] 之间的区别,最好通过示例进行演示。 最佳答案 #[cfg(test)] 标记仅当启用 test 配置选项时才编
当我来的时候,我正在寻找一个很好的解决方法来保持我的 .tmux.conf 文件在系统之间保持一致(我有 OS X 和 Ubuntu,它们有不同的复制/粘贴支持技术)在这条提供解决方案的评论中:htt
所以我有这个主 package Hibernate; import java.util.List; import org.hibernate.Session; import org.hibernate
我的项目根文件夹中有hibernate.cfg.xml文件。 如果我运行的应用程序包含: SessionFactory sessionFactory = new Configuration().con
我收到上述错误。我的 Web 应用程序中已有 xml 文件 hibernate.cfg.xml。除此之外,我在 WebINF lib 文件夹下有 hibernate 所需的完整 jar 文件。 这是完
我在 IntelliJ IDE 中的 hibernate.cfg.xml 有问题。 这是我的 hibernate 配置文件: org.postgresql
我正在尝试使用 pgadmin3 连接到 ubuntu 中的 Postgresql9.1。我的 Pgadmin3 GUI 工具没有提供任何通过右键单击数据库来创建表的选项,但它在我看到的一些视频中可用
您好,我的项目 CFG 文件中的路径列表太长,我如何定义像 $(BDS) 这样的路径快捷方式谢谢 最佳答案 “选项”对话框 ->“环境选项”->“环境变量”。该页面有一个“用户覆盖”部分。这就是您定义
对于 LR 解析器,FIRST 集定义如下 ( source ): FIRST(A) is the set of terminals which can appear as the first ele
我有一种用 CFG 表示的相当简单的语言。 S → A z A → A y A | A x A | A w | v 因为有左递归,递归下降解析器不会削减它。但是,我还需要找到所有可能的解释
Hibernate 的常用配置文件主要分为 2 种:核心配置文件(hibernate.cfg.xml)和映射文件(Xxx.hbm.xml),它们主要用于配置数据库连接、事务管理、Hibernate 本
出于测试目的,我需要 cfg 始终为真/假。对于 true 我使用 #[ cfg( target_pointer_width = "64") ] ... 但显然不够通用。表达 cfg 以获得必要值(v
我有以下常量: const IS_WSL: bool = is_wsl!(); 我希望能够将它与 cfg 属性一起使用来执行条件编译。像这样的东西: #[cfg(const = "IS_WSL")]
我知道给定一个特定的上下文无关语法,要检查它是否有歧义,需要检查是否存在任何可以以不止一种方式派生的字符串。这是不可判定的。 但是,我有一个更简单的问题。给定一个特定的上下文无关文法和一个特定的字符串
以下文法有左递归: T -> Tx | TYx | YX | x X -> xx Y -> Yy | Yx | y 你如何去除左递归。我阅读了维基百科的解释,但我对 CFG 还很陌生,所以它没有多大意
我想将 $cfg['RowActionLinksWithoutUnique'] 设置为 TRUE 以便我可以在 phpMyAdmin 中编辑数据而无需任何主键,但在检查 config.inc.php
考虑以下上下文无关文法的扩展,它允许规则在左侧有一个(或多个)终结符在非终结符的右侧。即形式规则: A b -> ... 右手边可以是任何东西,就像在上下文无关文法中一样。特别是不是 要求,右侧将在末
我是一名优秀的程序员,十分优秀!