diff --git a/spring-rest/src/main/java/org/baeldung/config/FaviconConfiguration.java b/spring-rest/src/main/java/org/baeldung/config/FaviconConfiguration.java new file mode 100644 index 0000000000..78a2a3eb2c --- /dev/null +++ b/spring-rest/src/main/java/org/baeldung/config/FaviconConfiguration.java @@ -0,0 +1,44 @@ +package org.baeldung.config; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping; +import org.springframework.web.servlet.resource.ResourceHttpRequestHandler; + +@Configuration +public class FaviconConfiguration { + @Bean + public SimpleUrlHandlerMapping myFaviconHandlerMapping() { + 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/produceimage/images"); + List locations = Arrays.asList(classPathResource); + requestHandler.setLocations(locations); + return requestHandler; + } + + //@Controller + static class FaviconController { + + @RequestMapping(value="favicon.ico", method=RequestMethod.GET) + @ResponseBody + void favicon() {} + } +} diff --git a/spring-rest/src/main/resources/application.properties b/spring-rest/src/main/resources/application.properties index dd7e4e2f2d..5ea345c395 100644 --- a/spring-rest/src/main/resources/application.properties +++ b/spring-rest/src/main/resources/application.properties @@ -1,2 +1,3 @@ server.port= 8082 -server.servlet.context-path=/spring-rest \ No newline at end of file +server.servlet.context-path=/spring-rest +spring.mvc.favicon.enabled=false \ No newline at end of file diff --git a/spring-rest/src/main/resources/com/baeldung/produceimage/images/favicon.ico b/spring-rest/src/main/resources/com/baeldung/produceimage/images/favicon.ico new file mode 100644 index 0000000000..64105ac11c Binary files /dev/null and b/spring-rest/src/main/resources/com/baeldung/produceimage/images/favicon.ico differ diff --git a/spring-rest/src/main/resources/static/favicon.ico b/spring-rest/src/main/resources/static/favicon.ico new file mode 100644 index 0000000000..64105ac11c Binary files /dev/null and b/spring-rest/src/main/resources/static/favicon.ico differ