0

When I start the app in browser it loads only html text and not the css and images. How can I fix it ?

This is my MvcConfig:

@Configuration
@EnableWebMvc
public class MvcConfig extends WebMvcConfigurationSupport {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry.addResourceHandler("/**")
            .addResourceLocations("classpath:/static/")
            .setCachePeriod(0);

    registry.addResourceHandler("/static/imag/**").addResourceLocations("/static/imag/**");
}


public void addViewControllers(ViewControllerRegistry registry) {

    registry.addViewController("/").setViewName("beers");
    registry.addViewController("/login").setViewName("login");

}

@Override
public void addCorsMappings(CorsRegistry registry) {
    registry.addMapping("/**");
}
}

And here is my project structure:

project Structure

Also I have in application.properties this code:

spring.mvc.static-path-pattern=/resources/**

And here is my controller:

@CrossOrigin("*")
@Controller
public class HomeController {


@GetMapping("/")
public String home(){
    return  "index";
}

@GetMapping("/login")
public String login(){
    return  "login";
}
}
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
slaviyy
  • 3
  • 4

0 Answers0