Skip to content

Load from resource from within a servlet #36

Description

@michelwilson

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions