Spring boot 2: отображение addResourceHandler для каждого языка возвращает 404 - PullRequest
1 голос
/ 29 января 2020

Я пытаюсь настроить обслуживание контента stati c на основе языкового параметра в URL-адресе, и я получаю 404, какое отображение неверно в следующем коде?

enter image description here

private PathResourceResolver getResolver() {
        return new PathResourceResolver() {
            @Override
            protected Resource resolveResourceInternal(HttpServletRequest request, String requestPath, List<? extends Resource> locations, ResourceResolverChain chain) {
                logger.info("REQ PATH :: " + requestPath + "   " + locations);
                return super.resolveResourceInternal(request, requestPath, locations, chain); //To change body of generated methods, choose Tools | Templates.
            }
        };
    }

И Stati c Структура папок:

enter image description here

Ниже полные журналы, которые показывают 404, когда я пытаюсь получить доступ к URL https://localhost:8443/fr

enter image description here

1 Ответ

0 голосов
/ 29 января 2020

Мне удалось решить проблему, если другие сталкивались с подобной проблемой, описанной ниже, решение работало для меня.

addResourceLocations путь должен заканчиваться /, иначе метод StringUtils applyRelativePath удалит последняя часть пути предоставлена, в моем случае en|fr|de..

    /**
     * Apply the given relative path to the given Java resource path,
     * assuming standard Java folder separation (i.e. "/" separators).
     * @param path the path to start from (usually a full file path)
     * @param relativePath the relative path to apply
     * (relative to the full file path above)
     * @return the full file path that results from applying the relative path
     */
    public static String applyRelativePath(String path, String relativePath) {
        int separatorIndex = path.lastIndexOf(FOLDER_SEPARATOR);
        if (separatorIndex != -1) {
            String newPath = path.substring(0, separatorIndex);
            if (!relativePath.startsWith(FOLDER_SEPARATOR)) {
                newPath += FOLDER_SEPARATOR;
            }
            return newPath + relativePath;
        }
        else {
            return relativePath;
        }
    }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...