Hibernate DTD没有从类路径加载,jar就在那里,仍然得到FileNotFoundException

问题描述 投票:2回答:1

我正进入(状态

Caused by:
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:
Configuration problem: Failed to import bean definitions from relative
location [hibernate.cfg.xml] Offending resource: ServletContext
resource [/WEB-INF/applicationContext.xml]; nested exception is
org.springframework.beans.factory.BeanDefinitionStoreException:
IOException parsing XML document from ServletContext resource
[/WEB-INF/hibernate.cfg.xml]; nested exception is
java.io.FileNotFoundException: class path resource
[org/hibernate/hibernate-configuration-3.0.dtd] cannot be opened
because it does not exist

这是我正在使用的依赖

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.5.Final</version>
        </dependency>

hibernate.cfg.xml -

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration SYSTEM
    "classpath://org/hibernate/hibernate-configuration-3.0.dtd">

使用import导入在spring中导入hibernate文件

<import resource="hibernate.cfg.xml"/>

Jar存在于maven依赖项中但仍无法加载DTD

java xml spring hibernate configuration
1个回答
2
投票

您无需在Spring应用程序上下文中导入hibernate.cfg.xml

所以,而不是:

<import resource="hibernate.cfg.xml"/>

您需要确保hibernate.cfg.xml位于jar中的某个位置。

如果您正在使用Maven,只需将其放在以下路径中:

${project.home}/src/main/resources/hibernate.cfg.xml

这样,hibernate.cfg.xml文件将在构建期间包含在模块jar中。

© www.soinside.com 2019 - 2024. All rights reserved.