Why does Spring Boot replace all of my icons with a Spring leaf icon?

(I looked at similar questions, but not one of them explains the strange behavior that I illustrate at the end of this question.)

I have a Spring Boot 1.3.5 application that insists on replacing my icon with the default boot flavored (green leaf). To solve this problem, I tried the following:

  • Install my own icon in my static root application.

The word on the street is that it should work. Unfortunately, it is not.

  1. Set the property spring​.​mvc​.​favicon​.​enabledto false.

It is intended to be disabled org​.​springframework​.​boot​.​autoconfigure​.​web​.​WebMvcAutoConfiguration​.​WebMvcAutoConfigurationAdapter​.​FaviconConfiguration, which appears to be responsible for servicing the default boot icon. By setting a breakpoint in this class, I was able to confirm that the beans defined in this class are not really created when the property is set to false.

Unfortunately, this also did not solve the problem.

  1. Implement your own favicon handler:

    @Configuration
    public class FaviconConfiguration {
    
        @Bean
        public SimpleUrlHandlerMapping faviconHandlerMapping() {
            SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
            mapping.setOrder(Integer.MIN_VALUE);
            mapping.setUrlMap(Collections.singletonMap("**/favicon.ico", faviconRequestHandler()));
            return mapping;
        }
    
        @Bean
        protected ResourceHttpRequestHandler faviconRequestHandler() {
            ResourceHttpRequestHandler requestHandler = new ResourceHttpRequestHandler();
            ClassPathResource classPathResource = new ClassPathResource("static/");
            List<Resource> locations = Arrays.asList(classPathResource);
            requestHandler.setLocations(locations);
            return requestHandler;
        }
    
    }
    

Unfortunately, you are also out of luck.

  1. Rename your favicon.ico badge to the .ico logo and simply point it to favicon links on my pages.

, , . curl icon.ico, Spring leaf. , , 404. , , ! , Spring Boot 404, , , !

, (PNG, JPG ..) .

, - Spring , , .: -)

. -?

ICO PNG, ( ), .

+4
2

, u ?

ur <head> :

<link rel="icon" type="image/png" href="images/fav.png" />

ur src/main/resources/static/images/

, html .

+1

spring:

Spring MVC

Spring spring MVC, .

Spring s :

  • ContentNegotiationViewResolver BeanNameViewResolver beans.
  • , WebJars (. ).
  • , GenericConverter, Formatter beans.
  • HttpMessageConverters (. ).
  • MessageCodesResolver (. ).
  • Static index.html.
  • Favicon.
  • ConfigurableWebBindingInitializer bean (. ).

: http://docs.spring.io/spring-boot/docs/1.4.1.RELEASE/reference/htmlsingle/#boot-features-spring-mvc-auto-configuration

, spring favicon, yml perperties files

spring.mvc.favicon.enabled=true # Enable resolution of favicon.ico.

, favicon . :

@Configuration
public static class FaviconConfiguration {

@Bean
public SimpleUrlHandlerMapping faviconHandlerMapping() {
    SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();
    mapping.setOrder(Integer.MIN_VALUE);
    mapping.setUrlMap(Collections.singletonMap("mylocation/favicon.ico",
            faviconRequestHandler()));
    return mapping;
}
}

: Spring :

UPDATE:

favicon.ico .

put favicon.ico in resources

, :

favicon

0

Source: https://habr.com/ru/post/1660218/


All Articles