(我研究了类似的问题,但没有一个能解释我在这个问题末尾说明的奇怪行为。)
\n\n我有一个 Spring Boot 1.3.5 应用程序,它坚持用 Boot 的默认图标(绿叶)替换我的图标。为了解决这个问题,我尝试了以下方法:
\n\n街上的传言是,这应该行得通。不幸的是,事实并非如此。
\n\nspring\xe2\x80\x8b.\xe2\x80\x8bmvc\xe2\x80\x8b.\xe2\x80\x8bfavicon\xe2\x80\x8b.\xe2\x80\x8benabled为 false。这应该禁用org\xe2\x80\x8b.\xe2\x80\x8bspringframework\xe2\x80\x8b.\xe2\x80\x8bboot\xe2\x80\x8b.\xe2\x80\x8bautoconfigure\xe2\x80\x8b.\xe2\x80\x8bweb\xe2\x80\x8b.\xe2\x80\x8bWebMvcAutoConfiguration\xe2\x80\x8b.\xe2\x80\x8bWebMvcAutoConfigurationAdapter\xe2\x80\x8b.\xe2\x80\x8bFaviconConfiguration,它似乎负责服务 Boot\ 的默认图标。通过在该类中设置断点,我能够确认当该属性设置为 false 时,该类中定义的 bean 确实不会被创建。
不幸的是,这也没有解决问题。
\n\n实现我自己的图标处理程序:
\n\n@Configuration\npublic class FaviconConfiguration {\n\n @Bean\n public SimpleUrlHandlerMapping faviconHandlerMapping() {\n SimpleUrlHandlerMapping mapping = new SimpleUrlHandlerMapping();\n mapping.setOrder(Integer.MIN_VALUE);\n mapping.setUrlMap(Collections.singletonMap("**/favicon.ico", faviconRequestHandler()));\n return mapping;\n }\n\n @Bean\n protected ResourceHttpRequestHandler faviconRequestHandler() {\n ResourceHttpRequestHandler requestHandler = new ResourceHttpRequestHandler();\n ClassPathResource classPathResource = new ClassPathResource("static/");\n List<Resource> locations = Arrays.asList(classPathResource);\n requestHandler.setLocations(locations);\n return requestHandler;\n …Run Code Online (Sandbox Code Playgroud)