0
votes

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...

1
Please post some logs and some configuration (pom.xml, application context if you have) to pastebin, and link them here.Gabor Garami
I am not a Spring Boot expert, because i use Spring framework manually, but maybe it is because you added an own Java configurator. I found this main class for using Spring boot: github.com/spring-projects/spring-boot/blob/v1.1.9.RELEASE/… You should extend SpringBootServletInitializerGabor Garami
You only need to extend SpringBootServlrtInitializer if you're building a war and deploying it to a servlet containerAndy Wilkinson

1 Answers

0
votes

Your index is being served from / – the root of the app. This means that you don't need the ../ prefix on the stylesheet's path. Try using resources/css/style.css instead. Alternatively you could use an absolute path (/resources/css/style.css), then it doesn't matter what path is serving the HTML.