I'm trying to load resources from the classpath in a servlet application. I would expect to be able to use
ConfigurationProperties.fromResource("application.properties")
or maybe
ConfigurationProperties.fromResource(SomeClass::class.java, "application.properties")
But both don't work. The first uses the system classloader, instead of the servlet classloader (which makes sense), but the second variant should work. In the code I see that the class that is passed in is used like this:
relativeToClass.getResource(resourceName)
For some reason this doesn't work. What does work is
relativeToClass.classLoader.getResource(resourceName)
Since I cannot passin the URL returned from this call, I have to resort to
val res = SomeClass::class.java.classLoader.getResource("application.properties")
ConfigurationProperties.fromFile(File(res.file))
Which isn't very elegant. Am I missing something here?
I'm trying to load resources from the classpath in a servlet application. I would expect to be able to use
or maybe
But both don't work. The first uses the system classloader, instead of the servlet classloader (which makes sense), but the second variant should work. In the code I see that the class that is passed in is used like this:
For some reason this doesn't work. What does work is
Since I cannot passin the
URLreturned from this call, I have to resort toWhich isn't very elegant. Am I missing something here?