在Tomcat服务器上的Eclipse中执行Spring Web项目的问题 [英] Issue in executing Spring Web project in Eclipse on Tomcat server
问题描述
作为Spring项目的一部分,我有一个spring-servlet.xml文件在WEB-INF目录下。此文件包含另一个资源xml文件,它具有数据源配置。
< import resource =classpath:$ {datasourceInclude} .xml />
现在,当使用Maven编译项目时,它会解析变量$ {datasourceInclude}并将其设置为导致具有适当值的spring-servlet.xml的适当值。
< import resource =classpath:datasourceLocal.xml/ >
但是当我尝试在Eclipse(Tomcat)中运行该项目时,我收到以下错误: p>
org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置问题:无法从URL位置导入bean定义[classpath:$ { data sourceInclude} .xml]
违规资源:ServletContext资源[/WEB-INF/spring-servlet.xml];嵌套异常是org.springframework.beans.factory.BeanDefinitionStoreException:从类路径资源[$ {datasourceInclude} .xml]中解析XML文档的IOException;嵌套异常是java.io.FileNotFoundException:类路径资源[$ {datasourceInclude} .xml]无法打开,因为它不存在
在org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java :68)
...
...
基本上当我开始Tomcat尝试从/ src / main / webapp / WEB-INF文件夹中选择spring-servlet.xml,该文件夹中有$ {datasourceInclude}变量。
我如何解决这个问题,所以我不必更改spring-servlet.xml并添加硬代码值代替$ {datasourceInclude}变量。
尝试在Maven项目配置页面中为资源过滤执行的目标列表添加 war:inplace
。
在项目中右键单击,然后转到属性> Maven>生命周期映射,然后添加 war:inplace
to 通过资源更改调用的目标,如下所示:
alt text http://img519.imageshack.us/img519/2817/screenshot009d.png
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.
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 http://img519.imageshack.us/img519/2817/screenshot009d.png
这篇关于在Tomcat服务器上的Eclipse中执行Spring Web项目的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!