更改/favicon.ico请求映射

时间:2019-03-13 16:20:48

标签: spring spring-boot spring-mvc

需要将favicon.ico的请求映射从/favicon.ico更改为/custom/favicon.ico。我已经将该映射设置为另一个对象(/account),现在每次我重新加载页面“ /account”时都会被调用。

@Configuration
public class FaviconConfiguration {

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

    @Bean
    protected ResourceHttpRequestHandler faviconRequestHandler() {
        ResourceHttpRequestHandler requestHandler = new ResourceHttpRequestHandler();
        requestHandler.setLocations(Arrays
                .<Resource> asList(new ClassPathResource("/")));
        return requestHandler;
    }

}

0 个答案:

没有答案