CSS not loading in Spring Boot

前端 未结 8 2165
渐次进展
渐次进展 2020-12-05 00:12

I am new to spring frame work and spring boot.I am trying to add the static html file with CSS,javascript,js. the file structure is

8条回答
  •  不思量自难忘°
    2020-12-05 00:56

    Put css files into webapp resources folder:

    src/main/webapp/resources/css/ 
    

    Configure resource handler

    public class WebConfig extends WebMvcConfigurerAdapter {
    
            @Override
            public void addResourceHandlers(ResourceHandlerRegistry registry) {
                    registry.addResourceHandler("/resources/**")
                            .addResourceLocations("/resources/");
            }
    

    Example projects:

    • https://github.com/spring-guides/tut-web/tree/master/6/complete
    • Spring Boot Service Template with Static Content

    Source:

    • Designing and Implementing a Web Application with Spring
    • Serving Web Content with Spring MVC

提交回复
热议问题