Jan 10th, 2013, 01:39 PM
Context import with classpath*:foo-*-context.xml
I would like to import additional context only if it exists on classpath to load a "plugin". I cannot use exact name in import tag as exception would occur when file is not found (plugin may not be loaded and app should work). I wanted to use wildcard expressions to load plugin context from classpath (packed in jar). However I find classpath*:foo-*-context.xml not finding context that is in my plugin jar (that is on the classpath). Context is in jar's root directory - I am using tomcat and spring 3.0.5. Is it normal that classpath* does not work with wildcards in context names? Or maybe it works in newer version?
I am also thinking about alternative solution like attaching into spring's context load process with some custom class and would look for my custom plugin context with even exact name and load it and does not throw exception when plugin is not loaded. Do you have any hint how I could achive it?
Jan 11th, 2013, 03:33 AM
Import with classpath*: and wildcard in context name does not work with root directories of jar - at least one subdirectory must be in the middle.
From spring documentation:
"Please note that "classpath*:" when combined with Ant-style patterns will only work reliably with at least one root directory before the pattern starts, unless the actual target files reside in the file system. This means that a pattern like "classpath*:*.xml" will not retrieve files from the root of jar files but rather only from the root of expanded directories. This originates from a limitation in the JDK's ClassLoader.getResources() method which only returns file system locations for a passed-in empty string (indicating potential roots to search)."