From 6db6f23a04a7c264412411f257070d6be821b8f2 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 5 Apr 2016 12:18:48 +0200 Subject: [PATCH] Quartz ResourceLoaderClassLoadHelper explicitly falls back to classpath lookup Issue: SPR-13706 --- .../quartz/ResourceLoaderClassLoadHelper.java | 48 +++++++++++-------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/ResourceLoaderClassLoadHelper.java b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/ResourceLoaderClassLoadHelper.java index 18ab755d56..726f9732d7 100644 --- a/spring-context-support/src/main/java/org/springframework/scheduling/quartz/ResourceLoaderClassLoadHelper.java +++ b/spring-context-support/src/main/java/org/springframework/scheduling/quartz/ResourceLoaderClassLoadHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,6 @@ package org.springframework.scheduling.quartz; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -73,43 +72,50 @@ public class ResourceLoaderClassLoadHelper implements ClassLoadHelper { } @Override - @SuppressWarnings("rawtypes") - public Class loadClass(String name) throws ClassNotFoundException { + public Class loadClass(String name) throws ClassNotFoundException { return this.resourceLoader.getClassLoader().loadClass(name); } @SuppressWarnings("unchecked") public Class loadClass(String name, Class clazz) throws ClassNotFoundException { - return loadClass(name); + return (Class) loadClass(name); } @Override public URL getResource(String name) { Resource resource = this.resourceLoader.getResource(name); - try { - return resource.getURL(); + if (resource.exists()) { + try { + return resource.getURL(); + } + catch (IOException ex) { + if (logger.isWarnEnabled()) { + logger.warn("Could not load " + resource); + } + return null; + } } - catch (FileNotFoundException ex) { - return null; - } - catch (IOException ex) { - logger.warn("Could not load " + resource); - return null; + else { + return getClassLoader().getResource(name); } } @Override public InputStream getResourceAsStream(String name) { Resource resource = this.resourceLoader.getResource(name); - try { - return resource.getInputStream(); + if (resource.exists()) { + try { + return resource.getInputStream(); + } + catch (IOException ex) { + if (logger.isWarnEnabled()) { + logger.warn("Could not load " + resource); + } + return null; + } } - catch (FileNotFoundException ex) { - return null; - } - catch (IOException ex) { - logger.warn("Could not load " + resource); - return null; + else { + return getClassLoader().getResourceAsStream(name); } }