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

Krysta
  • 57
  • 1
  • 11
  • Perhaps try `/css/bootstrap.css` instead – starcorn Apr 02 '16 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 – Krysta Apr 02 '16 at 19:36
  • 1
    Try solutions from this answers : http://stackoverflow.com/questions/27869267/loading-static-resources-with-spring-boot-and-thymeleaf , http://stackoverflow.com/questions/27583278/spring-boot-spring-mvc-thymeleaf-apache-tiles/27680210#27680210 – sanluck Apr 04 '16 at 02:28

2 Answers2

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

adithya
  • 29
  • 2
0

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