Skip to content
This repository has been archived by the owner on Sep 15, 2022. It is now read-only.

Using default assetsName might override previous assets #37

Open
explicat opened this issue Aug 22, 2015 · 1 comment
Open

Using default assetsName might override previous assets #37

explicat opened this issue Aug 22, 2015 · 1 comment

Comments

@explicat
Copy link

In my application I had defined two assets bundles like I had it with one assets bundle several times before.

bootstrap.addBundle(new ConfiguredAssetsBundle("/images", "/images")); bootstrap.addBundle(new ConfiguredAssetsBundle("/css", "/css"));

However, I did only get either of them working. By switching the order, the other got working. It was always the latter which behaved as expected.

After following the registration process to the ServletEnvironment, one can see that the bundle is registered as a servlet with the default asset name which it is assigned if no other asset name had been specified. Having been assigned the same asset name, the latter servlet overrides a previously registered servlet with the same name.

The simple solution is to specify an explicit and unique assets name for each assets bundle.

bootstrap.addBundle(new ConfiguredAssetsBundle("/images", "/images", "index.html", "Image assets"));
bootstrap.addBundle(new ConfiguredAssetsBundle("/css", "/css", "style.css", "Style assets"));

Nevertheless, for convenience I suggest to change the default assets name to something unique for each bundle, e.g. by incorporating the resource path and/or the uri path. I can think of only very few scenarios where someone would like to override his own assets configuration.

As I didn't know that the asset name actually had a meaning, I found this worth mentioning, maybe someone will stumble open the same problem one day.

@nbauernfeind
Copy link
Contributor

One thing worth noting is that if possible you will typically prefer to merge each mapping into a single bundle. See the documentation on the latest version of this project:
https://github.com/dropwizard-bundles/dropwizard-configurable-assets-bundle#multiple-uri-mappings

Additionally, if you do override the servlet, the dropwizard log at startup should emit a warning from this (probably varies depending on the version of dropwizard, this exists in 0.8.1) :

LOGGER.warn("Overriding the existing {} registered with the name: {}", type, name);

If there is anything else I can do for you, feel free to file an issue in the maintained repository (i.e. the dropwizard-bundles version).

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

No branches or pull requests

2 participants