perwendel/spark · warning

External static file location has already been set

Error message

External static file location has already been set

What it means

Service.externalStaticFileLocation logs 'External static file location has already been set' and skips reconfiguration when the external static resources were already configured. The second folder is silently ignored, so files from the new external folder are never served.

Solutions

  1. Configure the external folder exactly once during service init, before route mapping.
  2. Remove or guard the duplicate externalStaticFileLocation call (the warning points at the second call site).
  3. If the folder must change, create a new Service instance or restructure configuration instead of re-calling the method.
  4. Centralize static-file configuration in one place to prevent divergent init paths.

Example fix

// before
service.externalStaticFileLocation("/var/www");
service.externalStaticFileLocation("/opt/assets"); // ignored, warns
// after
service.externalStaticFileLocation("/opt/assets"); // single authoritative call
Defensive patterns

Strategy: validation

Validate before calling

if (!externalStaticConfigured) {
    service.externalStaticFileLocation("/opt/assets");
    externalStaticConfigured = true;
}

Prevention

When it happens

Trigger: Calling externalStaticFileLocation(...) twice, or after another call already invoked staticFilesConfiguration.configureExternal; calling it after static resources were already set up elsewhere during init.

Common situations: Multiple init() code paths both configuring external folders; deployment scripts injecting a different folder while code also sets one; duplicated bootstrap code between dev and prod config classes.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of perwendel/spark@1973e402f5 (2026-09-10). Data as JSON: /api/errors/edd44c80ecff5f98. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/spark/Service.java:366

        return this;
    }

    /**
     * Sets the external folder serving static files. <b>Observe: this method
     * must be called before all other methods.</b>
     *
     * @param externalFolder the external folder serving static files.
     * @return the object with external folder set
     */
    public synchronized Service externalStaticFileLocation(String externalFolder) {
        if (initialized && !isRunningFromServlet()) {
            throwBeforeRouteMappingException();
        }

        if (!staticFilesConfiguration.isExternalStaticResourcesSet()) {
            staticFilesConfiguration.configureExternal(externalFolder);
        } else {
            LOG.warn("External static file location has already been set");
        }
        return this;
    }

    /**
     * Unmaps a particular route from the collection of those that have been previously routed.
     * Search for previously established routes using the given path and unmaps any matches that are found.
     *
     * @param path the route path
     * @return <tt>true</tt> if this is a matching route which has been previously routed
     * @throws IllegalArgumentException if <tt>path</tt> is null or blank
     */
    public boolean unmap(String path) {
        return routes.remove(path);
    }

    /**
     * Unmaps a particular route from the collection of those that have been previously routed.

View on GitHub (pinned to 1973e402f5)