I know this question is ask often, but nothing of it works for me. I want to access the static resources, so I have a template in which I load "../resources/css/style.css".
But when I start the application the browser can not access the css file.
I am using Spring Boot 1.1.9 (also as parent in pom.xml).
My Structure is:
pom.xml
src/main/java
src/main/resources
src/main/resources/database
src/main/resources/templates
src/main/resources/templates/index.html
src/main/resources/static
src/main/resources/static/resources
src/main/resources/static/resources/css
src/main/resources/static/resources/fonts
src/main/resources/static/resources/img
src/main/resources/static/resources/js
(see http://i62.tinypic.com/of84jt.png)
My Controller:
package prototype.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class IndexController {
@RequestMapping("/")
public String stdRedirect(){
return "redirect:/index";
}
@RequestMapping(value="/index", method=RequestMethod.GET)
public String index(){
return "index";
}
}
Main:
@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Prototype {
public static void main(String[] args) throws Exception {
SpringApplication.run(Prototype.class, args);
}
}
I read that springboot automatic maps /static/ and /resources files...
SpringBootServletInitializer
– Gabor GaramiSpringBootServlrtInitializer
if you're building a war and deploying it to a servlet container – Andy Wilkinson