Spring MVC and Thymeleaf - only classpath mapping works












0















I wonder why I have to add "classpath:" always int he resourcelocations mapping for Spring, is this best practice?



Currently my project is setup like this, but I if I remove the "classpath", it does not find anything (and also I cannot provide a proper direct link). For integating bootstrap, I even had to use "webjars-locator" to make webjars accessible (due to missing transparency).



Can anyone explain, why classpath is required (and no direct link), and how I can find or restrucutre the project to make it work properly?



ResourceHandlers:
@Override



public void addResourceHandlers(final ResourceHandlerRegistry registry) {

registry.addResourceHandler(
"/webjars/**",
"/img/**",
"/css/**",
"/js/**")
.addResourceLocations(
"classpath:/META-INF/resources/webjars/",
"classpath:/static/img/",
"classpath:/static/css/",
"classpath:/static/js/");

}


index.htm:



<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<title>Spring Security Example</title>

<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<link rel="stylesheet" type="text/css" th:href="@{/css/style.css}" />
<link rel="stylesheet" type="text/css" th:href="@{/webjars/bootstrap/4.2.1/css/bootstrap.min.css}" />

</head>
<body>
<h1 class="color1">Hello, world! style</h1>

<p>
Click <a th:href="@{/hello}">here</a> to see a greeting.
</p>


<!-- include javascript in the footer -->
**<script type="text/javascript" th:src="@{/webjars/jquery/3.2.1/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/webjars/bootstrap/4.2.1/js/bootstrap.min.js}"></script>**
</body>
</html>


Project Structure










share|improve this question



























    0















    I wonder why I have to add "classpath:" always int he resourcelocations mapping for Spring, is this best practice?



    Currently my project is setup like this, but I if I remove the "classpath", it does not find anything (and also I cannot provide a proper direct link). For integating bootstrap, I even had to use "webjars-locator" to make webjars accessible (due to missing transparency).



    Can anyone explain, why classpath is required (and no direct link), and how I can find or restrucutre the project to make it work properly?



    ResourceHandlers:
    @Override



    public void addResourceHandlers(final ResourceHandlerRegistry registry) {

    registry.addResourceHandler(
    "/webjars/**",
    "/img/**",
    "/css/**",
    "/js/**")
    .addResourceLocations(
    "classpath:/META-INF/resources/webjars/",
    "classpath:/static/img/",
    "classpath:/static/css/",
    "classpath:/static/js/");

    }


    index.htm:



    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
    <head>
    <title>Spring Security Example</title>

    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />

    <link rel="stylesheet" type="text/css" th:href="@{/css/style.css}" />
    <link rel="stylesheet" type="text/css" th:href="@{/webjars/bootstrap/4.2.1/css/bootstrap.min.css}" />

    </head>
    <body>
    <h1 class="color1">Hello, world! style</h1>

    <p>
    Click <a th:href="@{/hello}">here</a> to see a greeting.
    </p>


    <!-- include javascript in the footer -->
    **<script type="text/javascript" th:src="@{/webjars/jquery/3.2.1/jquery.min.js}"></script>
    <script type="text/javascript" th:src="@{/webjars/bootstrap/4.2.1/js/bootstrap.min.js}"></script>**
    </body>
    </html>


    Project Structure










    share|improve this question

























      0












      0








      0








      I wonder why I have to add "classpath:" always int he resourcelocations mapping for Spring, is this best practice?



      Currently my project is setup like this, but I if I remove the "classpath", it does not find anything (and also I cannot provide a proper direct link). For integating bootstrap, I even had to use "webjars-locator" to make webjars accessible (due to missing transparency).



      Can anyone explain, why classpath is required (and no direct link), and how I can find or restrucutre the project to make it work properly?



      ResourceHandlers:
      @Override



      public void addResourceHandlers(final ResourceHandlerRegistry registry) {

      registry.addResourceHandler(
      "/webjars/**",
      "/img/**",
      "/css/**",
      "/js/**")
      .addResourceLocations(
      "classpath:/META-INF/resources/webjars/",
      "classpath:/static/img/",
      "classpath:/static/css/",
      "classpath:/static/js/");

      }


      index.htm:



      <!DOCTYPE html>
      <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
      <head>
      <title>Spring Security Example</title>

      <meta charset="utf-8" />
      <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <meta name="viewport" content="width=device-width, initial-scale=1" />

      <link rel="stylesheet" type="text/css" th:href="@{/css/style.css}" />
      <link rel="stylesheet" type="text/css" th:href="@{/webjars/bootstrap/4.2.1/css/bootstrap.min.css}" />

      </head>
      <body>
      <h1 class="color1">Hello, world! style</h1>

      <p>
      Click <a th:href="@{/hello}">here</a> to see a greeting.
      </p>


      <!-- include javascript in the footer -->
      **<script type="text/javascript" th:src="@{/webjars/jquery/3.2.1/jquery.min.js}"></script>
      <script type="text/javascript" th:src="@{/webjars/bootstrap/4.2.1/js/bootstrap.min.js}"></script>**
      </body>
      </html>


      Project Structure










      share|improve this question














      I wonder why I have to add "classpath:" always int he resourcelocations mapping for Spring, is this best practice?



      Currently my project is setup like this, but I if I remove the "classpath", it does not find anything (and also I cannot provide a proper direct link). For integating bootstrap, I even had to use "webjars-locator" to make webjars accessible (due to missing transparency).



      Can anyone explain, why classpath is required (and no direct link), and how I can find or restrucutre the project to make it work properly?



      ResourceHandlers:
      @Override



      public void addResourceHandlers(final ResourceHandlerRegistry registry) {

      registry.addResourceHandler(
      "/webjars/**",
      "/img/**",
      "/css/**",
      "/js/**")
      .addResourceLocations(
      "classpath:/META-INF/resources/webjars/",
      "classpath:/static/img/",
      "classpath:/static/css/",
      "classpath:/static/js/");

      }


      index.htm:



      <!DOCTYPE html>
      <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
      <head>
      <title>Spring Security Example</title>

      <meta charset="utf-8" />
      <meta http-equiv="X-UA-Compatible" content="IE=edge" />
      <meta name="viewport" content="width=device-width, initial-scale=1" />

      <link rel="stylesheet" type="text/css" th:href="@{/css/style.css}" />
      <link rel="stylesheet" type="text/css" th:href="@{/webjars/bootstrap/4.2.1/css/bootstrap.min.css}" />

      </head>
      <body>
      <h1 class="color1">Hello, world! style</h1>

      <p>
      Click <a th:href="@{/hello}">here</a> to see a greeting.
      </p>


      <!-- include javascript in the footer -->
      **<script type="text/javascript" th:src="@{/webjars/jquery/3.2.1/jquery.min.js}"></script>
      <script type="text/javascript" th:src="@{/webjars/bootstrap/4.2.1/js/bootstrap.min.js}"></script>**
      </body>
      </html>


      Project Structure







      spring spring-mvc thymeleaf






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 10:19









      NikoNiko

      44911445




      44911445
























          1 Answer
          1






          active

          oldest

          votes


















          0














          It is normal to use classpath. If you want to additionally load resources from root path use



          {"/", "classpath:/META-INF/resources/webjars/" ...}





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54004559%2fspring-mvc-and-thymeleaf-only-classpath-mapping-works%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            It is normal to use classpath. If you want to additionally load resources from root path use



            {"/", "classpath:/META-INF/resources/webjars/" ...}





            share|improve this answer




























              0














              It is normal to use classpath. If you want to additionally load resources from root path use



              {"/", "classpath:/META-INF/resources/webjars/" ...}





              share|improve this answer


























                0












                0








                0







                It is normal to use classpath. If you want to additionally load resources from root path use



                {"/", "classpath:/META-INF/resources/webjars/" ...}





                share|improve this answer













                It is normal to use classpath. If you want to additionally load resources from root path use



                {"/", "classpath:/META-INF/resources/webjars/" ...}






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 2 at 10:29









                Hitham S. AlQadheebHitham S. AlQadheeb

                12k33465




                12k33465
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54004559%2fspring-mvc-and-thymeleaf-only-classpath-mapping-works%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Mossoró

                    Error while reading .h5 file using the rhdf5 package in R

                    Pushsharp Apns notification error: 'InvalidToken'