Example #1
0
  private void initApiInfo() throws Exception {
    int apiCounter = 0;
    String[] beanNames = applicationContext.getBeanNamesForAnnotation(Controller.class);

    if (beanNames == null) {
      logger.info("No controller bean found. stop server and fix it.");
      throw new Exception("No controller bean found. stop server and fix it.");
    }

    Map<String, Object> checkMap = new HashMap<String, Object>();
    for (String beanName : beanNames) {
      logger.info("Controller bean found: " + beanName);
      Class<?> beanType = applicationContext.getType(beanName);

      Method[] methods = beanType.getMethods();
      for (Method method : methods) {
        if (method.getAnnotation(Api.class) != null
            && method.getAnnotation(RequestMapping.class) != null) {
          logger.info("Controller Api Method found: " + method.getName());
          if (checkMap.get(method.getName()) != null) {
            logger.info("Controller method name is duplicated! stop server and fix it.");
            throw new Exception("Controller method name is duplicated! stop server and fix it.");
          }
          checkMap.put(method.getName(), new Object());
          apiCounter++;
        }
      }
    }
    logger.info("Total {} api listed.", apiCounter);
    this.apiInfoCache = new ConcurrentHashMap<String, ApiInfo>();
  }