Created
February 28, 2023 14:34
-
-
Save strongant/ae9df4c5769ed9c789401f089f2b9ef6 to your computer and use it in GitHub Desktop.
获取到springboot中所有的请求url
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 UrlCollector implements ApplicationListener<ContextRefreshedEvent> { | |
private final List<String> urls = new ArrayList<>(); | |
@Autowired | |
public UrlCollector(RequestMappingHandlerMapping mapping) { | |
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods(); | |
map.forEach((info, method) -> { | |
PatternsRequestCondition condition = info.getPatternsCondition(); | |
Set<String> patterns = condition.getPatterns(); | |
urls.addAll(patterns); | |
}); | |
} | |
@Override | |
public void onApplicationEvent(ContextRefreshedEvent event) { | |
// 在启动时打印所有HTTP接口 | |
System.out.println("All HTTP interfaces:"); | |
urls.forEach(System.out::println); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment