0

I have my index.html thymeleaf page coming up but the CSS I am referencing on the page is not being found.

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

Here is what the deployed WAR looks like in Tomcat: enter image description here

The index.html is in the templates folder.

But I am getting the following error in the Chrome console:

GET http://localhost:8080/pocApp/css/bootstrap.min.css 404 (Not Found)

If I can get the index.html page fine why can't the thymeleaf servlet find that file? I've tried sticking the entire css directory into various places in the directory structure such as in WEB-INF and within WEB-INF/classes with no luck.

1 Answer 1

1

This site is quickly becoming my rubber duck as this is the second question of mine I've answered myself.

In my Spring 4 Java Config I have this:

public class SpringWebConfig extends WebMvcConfigurerAdapter {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/resources/**")
            .addResourceLocations("/resources/");
}

So I just had to restructure my directory and change the stylesheet URL.

New directory structure: enter image description here

And the new code snippet from my index.html

<link href="../resources/css/bootstrap.min.css" rel="stylesheet" th:href="@{/resources/css/bootstrap.min.css}" type="text/css"/>
Sign up to request clarification or add additional context in comments.

1 Comment

Welcome to my world.. I just assume I know more than most as I don't ask a lot of questions and when I do, I answer myself. :(

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.