I got a spring MVC application with a bunch of css and js files currently placed in the src/main/java/resources/assets
directory.
I read through the Spring Docs and some Tutorials on how to load these files for my templates using the ResourceHandlerRegistry class. I especially thought that the code snippets from this Tutorial would perfectly fit my project structure.
But I get always a 404 on my resource files.
Here is the Application/Configuration class I'm currently running with:
@Configuration
@EnableAutoConfiguration
@ImportResource("/applicationContext.xml") // only used for jpa/hibernate
@EnableWebMvc
@ComponentScan(basePackages = "at.sustain.docutools.viewer.presentation")
public class Application extends WebMvcConfigurerAdapter {
public static void main(String args[]) {
SpringApplication.run(Application.class);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/assets/**")
.addResourceLocations("classpath:/assets/");
registry.addResourceHandler("/css/**")
.addResourceLocations("/css/");
registry.addResourceHandler("/js/**")
.addResourceLocations("/js/");
}
}
And here a HEADer used in my HTML files (placed in resources/templates):
<head>
<!-- local Stylesheet -->
<link href="css/style.css" rel="stylesheet" />
<!-- local Javascript files -->
<script src="js/general.js"></script>
<script src="js/xmlhttp.js"></script>
<!-- local Javascript libraries -->
<script src="js/lib/filter.js"></script>
<script src="js/lib/jquery.fs.zoomer.js"></script>
<script src="js/lib/jquery.validate.js"></script>
</head>
The html file is loaded correctly through my controller classes but when trying to hit e.g. my style.css
file (http://localhost:8080/css/style.css
) I get an 404 as already mentioned.
I can't seem to find any more resources who could provide me with more information on this subject for Spring 4. Do I miss some configuration files? Or aren't the resource handler registrations fitting my structure? I'm looking forward to your responses.