views:

162

answers:

3

I'm working in a multi-module maven2 project using Spring and GWT. Let's say I have two subprojects: service and presentation. "service" contains the actual implementations of the services and "presentation" is in charge of wrapping them for GWT.

I have successfully loaded the Spring XML files that are in the WEB-INF directory (the same as web.xml), but I'm having problems with those XML files that should be loaded from the other modules.

My web.xml looks like this:

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>

 <context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>
      classpath:/spring-presentation.xml, classpath:/spring-services.xml
     </param-value>
 </context-param>

Here spring-presentation.xml is in the presentation project and spring-services.xml is in the service project. The spring-services.xml file is not being loaded. Am I missing something?

A: 

If the value starts with classpath: it won't look in WEB-INF/ folder it will look in classpath, which is WEB-INF/classes and direct contents of all the jar files under WEB-INF/lib/.

To make it look in WEB-INF/ folder you need to specify the value like this:

<param-value>
  /WEB-INF/spring-presentation.xml
  /WEB-INF/spring-services.xml
</param-value>

(you can put them on one line separated by comma, but I like it that way)

Vitaly Polonetsky
+1  A: 

I am guessing that the presentation project is compiled as WAR and the services project is compiled as a JAR. Also that the presentation project has dependency on the services project.

In such case, include the spring-services.xml file as a resource in the services project's pom so that it goes in its jar and since the presentation project has a dependency on the services project, the services jar will be put in the /WEB-INF/lib folder and then Spring will be able to load it from the classpath.

abhin4v
spring-services.xml is already in src/main/resources dir of the services project, so I guess there's no need to explicitly declare it in the project's pom
mgv
A: 

use

<import resource="classpath:spring-services.xml" />

at the top of spring-presentation.xml instead of referring to it from the web.xml

fco