Vojtěch Vojtěch - 1 year ago 58
Java Question

Getting all annotated controllers with @Controller

Is there a way to get a list of all Controllers, which were annotated with

? I would like to use them like:

public void addAll(List<Controller> controllers) throws Exception {
for (Controller controller : controllers) {


Answer Source


If you have annotated them with controller ... :

private ListableBeanFactory listableBeanFactory;


Map<String, Object> controllers;
controllers = listableBeanFactory.getBeansWithAnnotation(Controller.class);