1

I have the following file structure:

enter image description here

the MvcWebConfig file has this:

@Configuration
public class MvcWebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/resources/**")
                .addResourceLocations("/public", "classpath:/static/")
                .setCachePeriod(31556926);
    }
}

as read here that @EnableWebMVC shouldn't be used.

I've tried this in my HTML (which is placed in the templates folder)

<link rel="stylesheet" href="/static/css/bootstrap.min.css">
<link rel="stylesheet" href="static/css/bootstrap.min.css">
<link rel="stylesheet" href="resources/static/css/bootstrap.min.css">
<link rel="stylesheet" href="/resources/static/css/bootstrap.min.css">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="/css/bootstrap.min.css">

but none of these worked.

What am I doing wrong? I'm using Spring 5

Onilol
  • 1,315
  • 16
  • 41
  • check in browser network tab that from where it is trying to load the files. – Alien Dec 04 '18 at 12:03
  • `http://localhost:8080/` + any of these `static/css/bootstrap.min.css, /resources/static/css/bootstrap.min.css, css/bootstrap.min.css` – Onilol Dec 04 '18 at 12:10

1 Answers1

0

It can be maven that blocks your resources from being copied to your jar.

Resources to be copied are set in your pom.xml, for exemple :

<build>
    <finalName>app</finalName>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>application*.yaml</include>
                <include>dozer_mapping.xml</include>
            </includes>
        </resource>
    </resources>
</build>

Check if your resources are correctly copied in your build.

Oreste Viron
  • 3,592
  • 3
  • 22
  • 34