Announcement Announcement Module
Collapse
No announcement yet.
Import classpath*:... in xml file does not work Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Import classpath*:... in xml file does not work

    Hi,

    I'm using Spring 1.2.1 and I'd like to import xml files from multiple jar files. I know following syntax which only imports the file from the first found jar file:

    Code:
    <import resource="classpath&#58;mandatory/server.xml"/>
    But in my case I've got a lot of xml config files in directory mandatory. Further I'v got also another jar file, which contains also a directory "mandatory" filled with xml files. In an application context I would use config location classpath*:mandatory/*.xml but this will not work when I use it in xml configuration file:

    Code:
    <import resource="classpath*&#58;mandatory/*.xml"/>
    Can anyone tell me why this limitation exist?
    Why not allow this notation in xml configuration files too?

    Cheers,
    Martin

  • #2
    You can't mix wildcards patterns and the classpath*: (aggregation) prefix. There are a couple of useful threads on this:
    http://forum.springframework.org/showthread.php?t=10559
    http://forum.springframework.org/showthread.php?t=16613
    Last edited by robyn; May 16th, 2006, 03:10 AM.

    Comment


    • #3
      These are old threads. Have a look at class org.springframework.core.io.support.PathMatchingRe sourcePatternResolver. In method doFindPathMatchingJarResources you can see that it is today possible to lookup resources with ant style which are in jar files.

      Question:
      • Why does the import xml element can not contain the same config location(s) as I can have in an application context?

      Cheers,
      Martin

      Comment


      • #4
        These are old threads
        OK, but they're still accurate regarding classpath*:mandatory/*.xml aren't they?

        In method doFindPathMatchingJarResources you can see that it is today possible to lookup resources with ant style which are in jar files
        Guess I should've pointed this out. It's not that new though - I think its been available since 1-1-3 in mid Dec 2004.

        Anyway, glad you found a solution to the first part of you're problem

        Comment


        • #5
          I've entered a jira:
          http://opensource.atlassian.com/proj...rowse/SPR-1143

          Cheers,
          Martin

          Comment


          • #6
            Hmm..After reading PathMatchingResourcePatternResolver, it looks like classpath* prefix should work with wildcards in mutliple JARs. My test showed it worked for contexts in WEB/classes, but not with a mix in WEB-INF/classes, and some in JARs in WEB-INF/lib. Maybe a bug?

            Comment


            • #7
              OK - just to clarify after feedback from Juergen. classpath*: and wildcards do work, but not from the root directory within JARs. So for application contexts in the classpath at:

              /com/company/applicationContext.xml
              /com/company/applicationContext-ds.xml

              If they're in WEB-INF/classes the following will work:
              classpath*:**/applicationContext*.xml

              If they're in a JAR in WEB-INF/lib the following will work:
              classpath*:/com/**/applicationContext*.xml

              Comment


              • #8
                I facing the same issue, In my case the jar file (name: com.sitech.frame.dao.jar) which has the applicationContext.xml is in eclipse plugin's folder.

                applicationContext.xml is inside 'com.sitech.frame'
                I want to read it from an another jar (name: com.sitech.frame.ui.jar), which is also in the eclipse plugin's folder.

                ApplicationContext ctx = new FileSystemXmlApplicationContext("classpath*:/com/sitech/frame/applicationContext.xml");

                the above approach was not working as expected..

                When I tried

                System.out.println( ctx.getBeanDefinitionCount());

                it throws '0', but I have 23 bean ids in the applicationContext.xml file..

                Could any one help me to resolve this?

                Peter.

                Comment

                Working...
                X