I have a problem with the path to load resources like css and js. My Spring Boot host 2 "web site", the first web site is in resources/public and its all ok, the second web site is out the project.
|_Folder OUT The Project
|_First Web Site
|_css
|_index.css
|_js
|_index.js
|_index.html
|_Second Web Site
|_APP Spring Boot
This is the directory hierarchy. I use the optional configuration in spring to do all this.
@Configuration
@EnableWebMvc
public class StaticResourceConfiguration implements WebMvcConfigurer {
private static final String INDEX = "classpath:/public/";
private static final String FINAL = "file:./Folder OUT THE PROJECT/";
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**").addResourceLocations(INDEX);
registry.addResourceHandler("/Folder OUT THE PROJECT /**").addResourceLocations(FINAL);
}
}
If i go in localhost:8080/Folder OUT THE PROJECT/First Web Site/index.html, work. But index.html dont load /css/index.css and /js/index.js.
<link src="css/index.css" rel="stylesheet">
<script src="js/index.js"></script>
Because redirect to me in localhost:8080/js/index.js and same with css, localhost:8080/css/index.css, i dont know why, and i dont know how to fix. I cant know the name of the directories of the web sites in ("FOLDER OUT THE PROJECT"), because are generated by Spring .Jar (Generate Templates ... )
Thanks so much for your support.
Aucun commentaire:
Enregistrer un commentaire