1

Okay so as far as I know I'm using the correct set up for to link resources for Thymleaf resources in a spring boot project

Resources screenhot

Currently i'm linking them using the following:

<link href="../static/css/bootstrap.css" th:href="@{css/bootstrap.css}"
rel="stylesheet" media="screen" />

<link href="/css/bootstrap-theme.css"
th:href="@{css/bootstrap-theme.css}" rel="stylesheet" media="screen" />


<script type="text/javascript" src="/js/jquery-2.2.2.js"
th:src="@{js/jquery-2.2.2.js}"></script>


 <script type="text/javascript" src="/js/tether.js"
th:src="@{js/tether.js}"></script>

My routing path in my controller are

@RequestMapping(value = "/mvchome", method = RequestMethod.GET)
public String mvchome(Model model) {
    Post post = new Post();

    model.addAttribute("post", post);
    return "mvchome";
}

When I go to this page using /mvchome it loads the bootstrap properly, with the full form, however when I try to load /mvchome/ it loads the form properly but the bootstrap is not showing up.

no css page

working css

Also not sure if it matters but I'm also using spring security. Just would like to know if anyone knows why this is happening and ideas on how to fix it.

Thanks

***Modified bootstrap link as suggested and it still does not load the css on /mvchome/

Also I took a look at chrome in the sources and it seems that if it using /mvchome/ it changes the resources path

enter image description here

enter image description here

3
  • Perhaps try /css/bootstrap.css instead Commented Apr 2, 2016 at 16:38
  • i tried that but it still didnt work . I checked it out in google sources section and it looks like its changing the resource hierarchy Commented Apr 2, 2016 at 19:36
  • 1
    Try solutions from this answers : stackoverflow.com/questions/27869267/… , stackoverflow.com/questions/27583278/… Commented Apr 4, 2016 at 2:28

2 Answers 2

1

Same thing happened to me.....when i started spring boot with thymeleaf..... Try with the following as thymeleaf searches for resources in static folder there is no need to add '../'

    <link href="css/bootstrap.css"
    rel="stylesheet" media="screen" />

    <link href="css/bootstrap-theme.css" rel="stylesheet" media="screen" />


    <script type="text/javascript" src="js/jquery-2.2.2.js"></script>


    <script type="text/javascript" src="js/tether.js"></script>

If it still doesn't work(that's happened to me too) I changed Spring security, But for you I don't know whether you are using spring security or not

Sign up to request clarification or add additional context in comments.

Comments

0

i had a same problem, My solution is try ../css/bootstrap.css instead

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.