@Override
    protected AbstractFileResolvingResource getResource(String path) throws MalformedURLException {
        if (path == null || !path.startsWith("/")) {
            throw new MalformedURLException(path);
        }

        try {
            path = UriPath.canonical(path);

            final String addedPath = addPaths(baseResource, path);

            ClassPathResource resource = new ClassPathResource(addedPath);

            if (resource.exists() && path.endsWith("/")) {
                if (welcomeFile != null) {
                    resource = new ClassPathResource(addPaths(resource.getPath(), welcomeFile));
                } else {
                    // No welcome file configured, serve nothing since it's a directory
                    resource = null;
                }
            }

            if (resource != null && resource.exists()) {
                DirectoryTraversal.protectAgainstInClassPath(resource.getPath(), baseResource);
                return resource;
            } else {
                return null;
            }

        } catch (DirectoryTraversal.DirectoryTraversalDetection directoryTraversalDetection) {
            throw directoryTraversalDetection;
        } catch (Exception e) {
            if (LOG.isDebugEnabled()) {
                LOG.debug(e.getClass().getSimpleName() + " when trying to get resource. " + e.getMessage());
            }
        }
        return null;
    }
Constructor

@param baseResource the base resource path
@param welcomeFile  the welcomeFile
src/main/java/spark/resource/ClassPathResourceHandler.java