Spring classpath prefix difference

前端 未结 4 720
滥情空心
滥情空心 2020-11-28 00:51

Documented here it states

This special prefix specifies that all classpath resources that match the given name must be obtained (internally, thi

4条回答
  •  余生分开走
    2020-11-28 01:31

    The source code of Spring:

    public Resource[] getResources(String locationPattern) throws IOException {
       Assert.notNull(locationPattern, "Location pattern must not be null");
       //CLASSPATH_ALL_URL_PREFIX="classpath*:"
       if (locationPattern.startsWith(CLASSPATH_ALL_URL_PREFIX)) {
          // a class path resource (multiple resources for same name possible)
          if (getPathMatcher().isPattern(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()))) {
             // a class path resource pattern
             return findPathMatchingResources(locationPattern);
          }
          else {
             // all class path resources with the given name
             return findAllClassPathResources(locationPattern.substring(CLASSPATH_ALL_URL_PREFIX.length()));
          }
       }
       else {
          // Only look for a pattern after a prefix here
          // (to not get fooled by a pattern symbol in a strange prefix).
          int prefixEnd = locationPattern.indexOf(":") + 1;
          if (getPathMatcher().isPattern(locationPattern.substring(prefixEnd))) {
             // a file pattern
             return findPathMatchingResources(locationPattern);
          }
          else {
             // a single resource with the given name
             return new Resource[] {getResourceLoader().getResource(locationPattern)};
          }
       }
    }  
    

提交回复
热议问题