Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all controllers and request-mapping methods [closed]

In my Application, I wanted to list down all of my controllers and request method. Can anybody tell how can I detect the controller annotation in the application?

like image 935
Abhinav jha Avatar asked Dec 07 '25 09:12

Abhinav jha


1 Answers

You could get a starting point by:

1) Injecting

@Autowired
private ApplicationContext applicationContext;

2) Using

String[] getBeanNamesForType(@Nullable
                             Class<?> type)

If your controllers all extend a common base.

3) Use the

String[] getBeanDefinitionNames()

And then filter the ones ending in Controller.. if that is your common suffix for these.

For the methods themselves, you would most likely need to use reflection once you have the qualified controller class names.

like image 165
Maciej Kowalski Avatar answered Dec 09 '25 23:12

Maciej Kowalski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!