diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java index ec695ea368d9..be5b00bec86a 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/AbstractHandlerMapping.java @@ -78,6 +78,9 @@ public abstract class AbstractHandlerMapping extends WebApplicationObjectSupport implements HandlerMapping, Ordered, BeanNameAware { + final static String SUPPRESS_LOGGING_ATTRIBUTE = AbstractHandlerMapping.class.getName() + ".SUPPRESS_LOGGING"; + + /** Dedicated "hidden" logger for request mappings. */ protected final Log mappingsLogger = LogDelegateFactory.getHiddenLog(HandlerMapping.class.getName() + ".Mappings"); @@ -520,11 +523,13 @@ public final HandlerExecutionChain getHandler(HttpServletRequest request) throws HandlerExecutionChain executionChain = getHandlerExecutionChain(handler, request); - if (logger.isTraceEnabled()) { - logger.trace("Mapped to " + handler); - } - else if (logger.isDebugEnabled() && !DispatcherType.ASYNC.equals(request.getDispatcherType())) { - logger.debug("Mapped to " + executionChain.getHandler()); + if (request.getAttribute(SUPPRESS_LOGGING_ATTRIBUTE) == null) { + if (logger.isTraceEnabled()) { + logger.trace("Mapped to " + handler); + } + else if (logger.isDebugEnabled() && !DispatcherType.ASYNC.equals(request.getDispatcherType())) { + logger.debug("Mapped to " + executionChain.getHandler()); + } } if (hasCorsConfigurationSource(handler) || CorsUtils.isPreFlightRequest(request)) { diff --git a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java index 6c194b88d834..7411efe5bfff 100644 --- a/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java +++ b/spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java @@ -261,6 +261,7 @@ private static class AttributesPreservingRequest extends HttpServletRequestWrapp AttributesPreservingRequest(HttpServletRequest request) { super(request); this.attributes = initAttributes(request); + this.attributes.put(AbstractHandlerMapping.SUPPRESS_LOGGING_ATTRIBUTE, Boolean.TRUE); } private Map initAttributes(HttpServletRequest request) {