Skip to content

Commit db877e0

Browse files
committed
When running from JAR use application classloader for root resource scanning - Fixes #9582
1 parent f2573ef commit db877e0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

grails-core/src/main/groovy/grails/boot/config/GrailsAutoConfiguration.groovy

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import org.springframework.context.ResourceLoaderAware
1515
import org.springframework.context.annotation.Bean
1616
import org.springframework.core.io.DefaultResourceLoader
1717
import org.springframework.core.io.Resource
18+
import org.springframework.core.io.UrlResource
1819
import org.springframework.core.io.support.PathMatchingResourcePatternResolver
1920
import org.springframework.core.io.support.ResourcePatternResolver
2021
import org.springframework.core.type.classreading.CachingMetadataReaderFactory
@@ -213,23 +214,33 @@ class GrailsAutoConfiguration implements GrailsApplicationClass, ApplicationCont
213214
private static class ApplicationRelativeClassLoader extends URLClassLoader {
214215

215216
final URL rootResource
217+
final Class applicationClass
218+
final boolean jarDeployed
216219

217220
ApplicationRelativeClassLoader(Class applicationClass) {
218221
super([ IOUtils.findRootResource(applicationClass)] as URL[])
219222

220223
this.rootResource = getURLs()[0]
224+
this.applicationClass = applicationClass
221225
def urlStr = rootResource.toString()
226+
jarDeployed = urlStr.startsWith("jar:")
222227
try {
223228
def withoutBang = new URL("${urlStr.substring(0, urlStr.length() - 2)}/")
224229
addURL(withoutBang)
230+
225231
} catch (MalformedURLException e) {
226232
// ignore, running as a WAR
227233
}
228234
}
229235

230236
@Override
231237
Enumeration<URL> getResources(String name) throws IOException {
232-
return super.findResources(name)
238+
if(jarDeployed && name == '') {
239+
return applicationClass.getClassLoader().getResources(name)
240+
}
241+
else {
242+
return super.findResources(name)
243+
}
233244
}
234245
}
235246

0 commit comments

Comments
 (0)