Issue in executing Spring Web project in Eclipse on Tomcat server

纵饮孤独 提交于 2019-12-08 12:03:39

问题


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.


回答1:


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:




回答2:


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?



来源:https://stackoverflow.com/questions/2416155/issue-in-executing-spring-web-project-in-eclipse-on-tomcat-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!