Skip to content

Instantly share code, notes, and snippets.

@gkhays
Last active February 14, 2020 16:12
Show Gist options
  • Save gkhays/7de5f203f96304525362ad92d7b9e959 to your computer and use it in GitHub Desktop.
Save gkhays/7de5f203f96304525362ad92d7b9e959 to your computer and use it in GitHub Desktop.
Extend Dropwizard

Out of the Box Things for Dropwizard

Push the boundaries of Dropwizard.

Load Classes on Classpath

The fix for Issue #1314 should load classes on the classpath.

test/resources/example.txt
whee
@Test
public void readsFileContents() throws Exception {
	try (InputStream input = provider.open("example.txt")) {
		assertThat(new String(ByteStreams.toByteArray(input), StandardCharsets.UTF_8).trim()).isEqualTo("whee");
	}
}
public class ResourceConfigurationSourceProvider implements ConfigurationSourceProvider {

    @Override
    public InputStream open(String path) throws IOException {
        return getClass().getClassLoader().getResourceAsStream(path);
    } 

}

References

  1. ConfigurationSourceProvider #1314
  2. Updating Dropwizard config at runtime
  3. Dropwizard guice integration
  4. Can DropWizard serve assets from outside the jar file?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment