[SpringBoot]favicon.icon 사용하기.

2021. 3. 12. 12:00카테고리 없음

728x90

기존에 favicon을 사용하기 위해서는
spring.mvc.favicon.enabled 옵션을 이용하라고 많이 나와있던데,
SpringBoot2.2부터 막힌거같다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
@Configuration
public class FaviconConfiguration {
 
    @Bean
    public SimpleUrlHandlerMapping customFaviconHandlerMapping() {
        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("com/baeldung/images/");
        List<Resource> locations = Arrays.asList(classPathResource);
        requestHandler.setLocations(locations);
        return requestHandler;
    }
}
cs

 

요렇게 하면 나옴.

 

 

참고.

www.baeldung.com/spring-boot-favicon

 

Guide to the Favicon in Spring Boot | Baeldung

Learn how to customize the favicon in a Spring Boot application.

www.baeldung.com

 

 

 

 

728x90