Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Load from resource from within a servlet #36

Open
michelwilson opened this issue Jan 29, 2019 · 0 comments
Open

Load from resource from within a servlet #36

michelwilson opened this issue Jan 29, 2019 · 0 comments

Comments

@michelwilson
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant