Не удается загрузить статические ресурсы из пользовательского taglib в Spring Boot - PullRequest
0 голосов
/ 25 января 2019

Я экспериментирую с Spring Boot и пытаюсь создать простой пользовательский тег, который действует как оболочка для моих JSP.Хотя у меня есть проблемы с загрузкой статических ресурсов из этого тега.

Ниже приведена моя структура каталогов:.

    ├── pom.xml
    ├── src
    │   ├── main
    │   │   ├── java
    │   │   │   └── com....
    │   │   ├── resources
    │   │   │   ├── application.properties
    │   │   │   ├── static
    │   │   │   |    ├── js
    │   │   │   |    ├── css
    │   │   │   |    └── libraries
    │   │   │   |          ├── jquery
    │   │   │   |                └── jquery.min.js
    │   │   │   |          ├── bootstrap
    │   │   │   |          ├── ...
    │   │   └── webapp
    │   │          └── WEB-INF
    │   │                ├── tags
    │   │                     └── main.tag
    │   │                ├── tlds
    │   │                ├── views
    │   │                     └── productDetails.jsp
    │   └── test
    │       └── java
    │           └── com

Всякий раз, когда страница загружается, содержимое в порядке, потому что я могу проверить HTMLстраница, но статические ресурсы не загружаются, что приводит к ошибкам консоли:

jquery.min.js:1 Failed to load resource: the server responded with a status of 404 ()
localhost/:1 Refused to apply style from 'http://localhost:8080/product/libraries/bootstrap/bootstrap.min.css' because its MIME type ('application/json') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
jquery.min.js:1 Failed to load resource: the server responded with a status of 404 ()
localhost/:1 Refused to apply style from 'http://localhost:8080/product/libraries/bootstrap/bootstrap.min.css' because its MIME type ('application/json') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Интересно то, что когда я меняю ресурсы по ссылкам CDN, все работает нормально.Каким-то образом это происходит с Spring, но я не могу понять, что.


main.tag выглядит следующим образом:
<%@ tag description="Core Page Template" %>

<%@ attribute name="header" fragment="true" required="false" %>
<%@ attribute name="jsImports" fragment="true" required="false" %>

<!DOCTYPE html>

<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <link rel="stylesheet" href="libraries/bootstrap/bootstrap.min.css">
    <!-- I've even tried all possible combinations of that link
         (e.g /libraries or /static/libraries or I moved the whole directory
         under /webapp or /webapp/WEB-INF/)
         but nothing seem to work. All the time I get 404 responses from the
         server -->
    <jsp:invoke fragment="header"/>
</head>
<body>

<jsp:doBody/>

<script src="libraries/jquery/jquery.min.js"></script>
</body>
</html>

Что я могу использовать из JSP, например:

<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="tt" tagdir="/WEB-INF/tags" %>

<tt:main>
    <jsp:attribute name="header">
            <title>Products - List</title>
    </jsp:attribute>
    <jsp:body>
        Do body....
    </jsp:body>
</tt:main>
...