Announcement Announcement Module
Collapse
No announcement yet.
What's the trick to use PathMatchingResourcePatternResolver? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • What's the trick to use PathMatchingResourcePatternResolver?

    I'm using Spring 1.1.2 and I am trying to use the new PathMatchingResourcePatternResolver class that Juergen added.
    Code:
    <bean id="SessionFactory" name="recruit.SessionFactory user.SessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
        ...
        <property name="mappingLocations">
            <list>
                <value>classpath*&#58;com/**/domain/*.hbm.xml</value>
            </list>
        </property>
        ...
    </bean>
    Whatever I seem to try, Spring can't seem to resolve my resource. I end up with:

    java.io.FileNotFoundException: Could not open class path resource [classpath*:com/**/domain/*.hbm.xml]

    I did notice in the JavaDoc that the classpath has to begin with an existing root path instead of a wildcard like I would prefer, but I added the root path without any further success.

  • #2
    I ran into exactly the same problem before, and the trick is to remove "<list>" and "</list>".

    Comment


    • #3
      Thanks. That did resolve my problem.

      I guess that also means that the developer cannot specify more than one mapping location if they are using pattern matching?

      Perhaps this is a bug?

      Comment


      • #4
        Spoke too soon. Your suggestion resolved the error condition, but it doesn't seem to help locating my resources.

        Tracing through the Spring code in the PathMatchingResourcePatternResolver it looks like the prefix of "classpath*:" does not support wildcard searching.

        When I change my pattern to "classpath:com/**/domain/*.hbm.xml" I get wildcard searching, but the resources I am looking for is not found.

        The class has a method named findPathMatchingFileResources that asks the classloaded to locate the root of my search pattern. In my case this is "/com". It returns the first classpath directory that has a directory named "/com". It then searches this directory for the rest of my wildcard path subset. That is correct behavior.

        However, it only searches that first classpath directory! It never checks the many other directories that can be on the classpath!

        Must be a bug. I'm using Spring 1.1.2.

        Comment


        • #5
          I upgraded to Spring 1.1.3 and the PathMatchingResourcePatternResolver does now look into all of the classpath directories (and jars), so my issue is resolved. BTW, the correct syntax is now:
          Code:
          <property name="mappingLocations">
              <value>classpath*&#58;com/**/domain/*.hbm.xml</value>
          </property>
          Note that the "classpath*" is needed. In fact, I'm not sure when you would use classpath: instead of classpath*: ?

          Also, I'm confused how you would combine the wildcard search with a different wildcard search or a simple non-wildcard lookup, since <list> is not supported?

          Comment


          • #6
            Oops, sorry, I should have made clear that I'm running 1.1.3 and I learned about the difference of "classpath", "classpath*", etc. from the Javadoc of PathMatchingResourcePatternResolver.

            For your second question, I would like to know the answer too.

            Comment


            • #7
              I don't know if you want to achieve this.. but my answer was to build a custom FactoryBeanLoader for spring to load all the hibernate mappings that finds in a classpath.

              http://hiberforum.org/blojsom/blog/j...ng_Spring.html

              Comment

              Working...
              X