UserController userController = new UserController(); Class<? extends UserController> clazz = userController.getClass(); Stream.of(clazz.getDeclaredFields()).forEach(field -> { // check the member variable whether annotated with @MyAutowired MyAutowired annotation = field.getAnnotation(MyAutowired.class); if (annotation != null) { field.setAccessible(true); // get the class type of the field Class<?> type = field.getType(); try { Object o = type.newInstance(); field.set(userController, o); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); }