Exemplo n.º 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());
 }
Exemplo n.º 2
0
 /**
  * Create a new ClassPathResource for Class usage. The path can be relative to the given class, or
  * absolute within the classpath via a leading slash.
  *
  * @param path relative or absolute path within the class path
  * @param clazz the class to load resources with
  * @see java.lang.Class#getResourceAsStream
  */
 public ClassPathResource(String path, Class<?> clazz) {
   Assert.notNull(path, "Path must not be null");
   this.path = StringUtils.cleanPath(path);
   this.clazz = clazz;
 }
Exemplo n.º 3
0
 /**
  * Create a new ClassPathResource with optional ClassLoader and Class. Only for internal usage.
  *
  * @param path relative or absolute path within the classpath
  * @param classLoader the class loader to load the resource with, if any
  * @param clazz the class to load resources with, if any
  */
 protected ClassPathResource(String path, ClassLoader classLoader, Class<?> clazz) {
   this.path = StringUtils.cleanPath(path);
   this.classLoader = classLoader;
   this.clazz = clazz;
 }