views:

398

answers:

2

Hi All,

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.

A: 

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?

hbunny
This is done at compile time by Maven. I have specified few maven profiles that loads resource bundle files that have values for variables.
viralpatel
Then how do you expect this to work when running from Eclipse? Are you using a Maven plug-in in Eclipse, like M2E?
hbunny
Yes, I am using Maven plugin M2E for Eclipse. My question is how to configure Eclipse to change the variables in spring-servlet.xml file before it is being loaded in Tomcat.
viralpatel
+1  A: 

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

Pascal Thivent