Skip to content

Instantly share code, notes, and snippets.

@xinyii
Created April 21, 2021 06:28
Show Gist options
  • Save xinyii/fb63594a7b3516d8a1cf6e4f51fc10e0 to your computer and use it in GitHub Desktop.
Save xinyii/fb63594a7b3516d8a1cf6e4f51fc10e0 to your computer and use it in GitHub Desktop.
[Spring Controller Scan] #spring
@Component
public class EndpointsListener implements ApplicationListener<ContextRefreshedEvent> {
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
ApplicationContext applicationContext = event.getApplicationContext();
applicationContext.getBean(RequestMappingHandlerMapping.class).getHandlerMethods()
.forEach((requestMappingInfo, handlerMethod) -> {
Set<RequestMethod> methods = requestMappingInfo.getMethodsCondition().getMethods();
Set<String> patterns = requestMappingInfo.getPatternsCondition().getPatterns();
log.info("Method: {} Path: {}", methods, patterns);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment