CSS breakage on page reload running on Spring Boot

66 Views Asked by At

I have an angular application packaged in Spring, in the resorce/static folder, in spring there is a configuration class to always look at the html, it happens that when reloading the page there is a css break presenting a quick html and returning to the source page. this is my targeting class:

  `  @Override
     public void addResourceHandlers(ResourceHandlerRegistry registry) {
      registry.addResourceHandler("/**")
            .addResourceLocations("classpath:/static/")
            .resourceChain(true)
            .addResolver(new PathResourceResolver() {
                @Override
                protected Resource getResource(String resourcePath, Resource location) throws       IOException {
                    Resource requestedResource = location.createRelative(resourcePath);
                    return requestedResource.exists() && requestedResource.isReadable() ?  requestedResource
                            : new ClassPathResource("/static/index.html");
                }
            });
   }`
 

image

I tried making a configuration that authorizes to control access to different parts of your Spring Boot application, allowing public access to some static resources, while requiring authentication for other parts of the application. Authentication is performed using HTTP basic authentication. But it didn't work.

          ` protected void configure(HttpSecurity http) throws Exception {
            http.authorizeRequests()
            .antMatchers("/css/**", "/js/**", "/assets/**").permitAll()
            .antMatchers("/files/**", "/other-files/**", "/resources/**").permitAll()
            .anyRequest().authenticated()
            .and()
            .httpBasic();
     }`
0

There are 0 best solutions below