PDA

View Full Version : Loading spring xml's using classpath:*


opsb
Mar 20th, 2006, 06:17 AM
In my web.xml I have my context locations specified as

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:spring*.xml</param-value>
</context-param>

All of my spring config files are named in the pattern spring*.xml and are in the root of the classpath.

Unfortunately the dispatcherservlet doesn't seem to pick up these files. I realise that I could just use the absolute path to the files but I'm also using spring xml's that are located in a jar on the classpath. I want the xml's that are outside of the jar to be able to see the xml's inside the jar and for the dispatcherservlet config to be able to see everything. Has anyone done something similar?

opsb
Mar 20th, 2006, 07:49 AM
It turns out that the problem was that you can't use wildcards when using the classpath: prefix. If I refence each spring file explicitly it works fine.

This is a bit of a pain however as I have 13 spring files and I don't really want to have to explicitly add them to the web.xml everytime I use the jar. Does anyone have any ideas?

thiebal
Apr 26th, 2006, 03:35 PM
It works for me with spring 2.0-m4:


<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext-*.xml</param-value>
</context-param>


Cedric

thiebal
Aug 23rd, 2006, 04:49 PM
In fact it seems that the wildcard works only for XML files that are not in jar...

I did a test and when the XML is in the 'classes' folder it works but when I package it in a jar in the 'lib' folder, this XML is not loaded.

Is this normal for Spring? We should not make any differences when we access application contexts form 'classes' folder or from jars in lib 'folder'.

Cedric

avec
Sep 26th, 2006, 06:02 AM
What is the final answer to this?

We have a lot of spring config files. Each one is spesified in web.xml, but we would like to reference it in the form classpath*:context.xml or in the form classpath:*-context.xml. This is preferable since the project is growing and additional context.xml files emerges. All of our spring config files is packed in jars.

Costin Leau
Sep 26th, 2006, 06:50 AM
Take a look at the reference documentation and the explanation on classpath resources and wildcards (chapter 4.7). If you have multiple jars (i.e. multiple classpaths) use the classpath* instead of classpath.