예제 #1
0
 /**
  * Create a new ClassPathResource for ClassLoader usage. A leading slash will be removed, as the
  * ClassLoader resource access methods will not accept it.
  *
  * @param path the absolute path within the classpath
  * @param classLoader the class loader to load the resource with, or <code>null</code> for the
  *     thread context class loader
  * @see java.lang.ClassLoader#getResourceAsStream(String)
  */
 public ClassPathResource(String path, ClassLoader classLoader) {
   Assert.notNull(path, "Path must not be null");
   String pathToUse = StringUtils.cleanPath(path);
   if (pathToUse.startsWith("/")) {
     pathToUse = pathToUse.substring(1);
   }
   this.path = pathToUse;
   this.classLoader = (classLoader != null ? classLoader : ClassUtils.getDefaultClassLoader());
 }
예제 #2
0
  /** This implementation returns a description that includes the class path location. */
  public String getDescription() {
    StringBuilder builder = new StringBuilder("class path resource [");

    if (this.clazz != null) {
      builder.append(ClassUtils.classPackageAsResourcePath(this.clazz));
      builder.append('/');
    }

    builder.append(this.path);
    builder.append(']');
    return builder.toString();
  }