Created
April 23, 2019 09:59
-
-
Save duypm/23e584568dd15d9b64af3c31509777aa to your computer and use it in GitHub Desktop.
Spring - Logging all request mappings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class RequestMappingLogger implements ApplicationListener<ContextRefreshedEvent> { | |
public static final Logger logger = LoggerFactory.getLogger(RequestMappingLogger.class); | |
@Override | |
public void onApplicationEvent(ContextRefreshedEvent event) { | |
RequestMappingHandlerMapping requestMappingHandlerMapping = event.getApplicationContext().getBean(RequestMappingHandlerMapping.class); | |
for (Map.Entry<RequestMappingInfo, HandlerMethod> entry: requestMappingHandlerMapping.getHandlerMethods().entrySet()) { | |
Method handler = entry.getValue().getMethod(); | |
for (String pattern : entry.getKey().getPatternsCondition().getPatterns()) { | |
for (RequestMethod method : entry.getKey().getMethodsCondition().getMethods()) { | |
String[] strings = {pattern, method.name(), handler.getDeclaringClass().getName() + "#" + handler.getName()}; | |
logger.debug(JoinerUtil.byComma(strings)); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment