文件root-context.xml应该放在Java Hibernate项目的根目录中。

huangapple go评论64阅读模式
英文:

Where should the file root-context.xml for a Java Hibernate project be located

问题

我有一个刚安装的 Eclipse 版本:版本:2020-09(4.17.0)
我正在尝试构建并部署一个 Spring Web 应用到 Tomcat 7。当我执行 maven-install 时,出现以下错误:

由于找不到 class path 资源 [root-context.xml],无法打开位于类路径资源 [root-context.xml] 的 XML 文档的 IOException;嵌套异常是 java.io.FileNotFoundException: 无法打开类路径资源 [root-context.xml],因为它不存在。

我已将 root-context.xml 添加到 src/main/webapp/WEB-INF/spring,并将其添加到我的构建路径中。我不知道是否需要将它移动到其他地方。

英文:

I have a freshly installed version of eclipse: Version: 2020-09 (4.17.0)
I am trying to build and deploy a spring web application to Tomcat 7. I'm getting the following error when I do a maven-install:

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [root-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [root-context.xml] cannot be opened because it does not exist

I've added root-context.xml in src/main/webapp/WEB-INF/spring to my build path. I don't know if I need to move it somewehre.

答案1

得分: 1

尝试将 root-context.xml 移动到 src/main/resources 目录,它将被包含在 Eclipse 的目标文件夹中并且能够正确运行。

如果你的测试路径中有测试文件,请在你的 pom.xml 文件中添加以下代码段:

<build>
    ...
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </testResource>
    </testResources>
    ...
</build>
英文:

Try moving root-context.xml to src/main/resources directory, it will be included in the eclipse target folder and run correctly.

and add this piece on yout pom.xml if you have test add in the test path

&lt;build&gt;
....
&lt;resources&gt;
    &lt;resource&gt;
        &lt;directory&gt;src/main/resources&lt;/directory&gt;
        &lt;filtering&gt;true&lt;/filtering&gt;
    &lt;/resource&gt;
&lt;/resources&gt;
&lt;testResources&gt;
    &lt;testResource&gt;
        &lt;directory&gt;src/test/resources&lt;/directory&gt;
        &lt;filtering&gt;true&lt;/filtering&gt;
    &lt;/testResource&gt;
&lt;/testResources&gt;
....
&lt;/build&gt;

huangapple
  • 本文由 发表于 2020年10月23日 02:49:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/64488692.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定