在 Tomcat 服务器上的 Eclipse 中执行 Spring Web 项目时出现问题

发布于 2024-08-24 13:09:06 字数 1428 浏览 8 评论 0原文

我有一个使用 Maven 来编译/构建的 Spring Web 项目。构建项目没有问题。我正在尝试在 Tomcat (v6) 服务器上的 Eclipse (3.3.2) 中运行该项目。

作为 Spring 项目的一部分,我在 WEB-INF 目录中有一个 spring-servlet.xml 文件。该文件包含另一个具有数据源配置的资源 xml 文件。

<import resource="classpath:${datasourceInclude}.xml"/>

现在,当使用 Maven 编译项目时,它会解析变量 ${datasourceInclude} 并将其设置为适当的值,从而生成具有适当值的 spring-servlet.xml。

<import resource="classpath:datasourceLocal.xml"/>

但是当我尝试在 Eclipse (Tomcat) 中运行该项目时,出现以下错误:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:${datasourceInclude}.xml]
Offending resource: ServletContext resource [/WEB-INF/spring-servlet.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [${datasourceInclude}.xml]; nested exception is java.io.FileNotFoundException: class path resource [${datasourceInclude}.xml] cannot be opened because it does not exist
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
...
...

基本上,当我启动 Tomcat 时,它会尝试从 /src/main/webapp/WEB-INF 文件夹中选择 spring-servlet.xml,其中包含 $ {datasourceIninclude} 变量。

谁能告诉我如何解决这个问题,这样我就不必更改 spring-servlet.xml 并添加硬代码值来代替 ${datasourceInclude} 变量。

I have a Spring web project that uses Maven to compile/build. There is no issue in building the project. I am trying to run the project in Eclipse (3.3.2) on Tomcat (v6) server.

As part of Spring project, I have a spring-servlet.xml file in WEB-INF directory. This file includes another resource xml file that has datasource configuration.

<import resource="classpath:${datasourceInclude}.xml"/>

Now when the project is compiled using Maven, it resolves the variable ${datasourceInclude} and set it with appropriate values resulting in spring-servlet.xml with proper values.

<import resource="classpath:datasourceLocal.xml"/>

But when I tried running the project in Eclipse (Tomcat), I am getting following error:

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:${datasourceInclude}.xml]
Offending resource: ServletContext resource [/WEB-INF/spring-servlet.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [${datasourceInclude}.xml]; nested exception is java.io.FileNotFoundException: class path resource [${datasourceInclude}.xml] cannot be opened because it does not exist
    at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
...
...

Basically when I starts Tomcat, it tries to pick the spring-servlet.xml from /src/main/webapp/WEB-INF folder which has ${datasourceInclude} variable.

Can anyone tell me how to fix this issue so that I dont have to change spring-servlet.xml and add hard code value in place of ${datasourceInclude} variable.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

魂ガ小子 2024-08-31 13:09:06

尝试将 war:inplace 添加到 Maven 项目配置页面中资源过滤执行的目标列表中。

右键单击您的项目,然后转到属性>梅文>生命周期映射并将war:inplace添加到资源更改时调用的目标,如下所示:

替代文本

Try to add war:inplace to the list of goals executed for resource filtering in the Maven project configuration page.

Right-click on your project, then go to Properties > Maven > Lifecycle Mapping and add war:inplace to the Goals to invoke on resource changes as shown below:

alt text

谁的年少不轻狂 2024-08-31 13:09:06

谁负责解析 Spring XML 中的属性/变量名称?这是通过 Maven 在编译时完成的还是应该在运行时发生?如果在运行时,您是否使用Spring的PropertyPlaceholderConfigurer?

Who's responsible for resolving the property/variable name in your Spring XML? This is done at compile time via Maven or is it supposed to happen at runtime? If at runtime, are you using Spring's PropertyPlaceholderConfigurer?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文