WebServiceMethodCountBeanFactoryPostProcessor implements BeanFactoryPostProcessor { @Override public void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory) throws BeansException { Map<RequestMethod, Integer> methodsCount = new HashMap<RequestMethod, Integer>(); String[] beanDefinitionNames = beanFactory.getBeanDefinitionNames(); for (String beanDefinitionName : beanDefinitionNames) { Class<?> type = beanFactory.getType(beanDefinitionName); RestController annotation = type.getAnnotation(RestController.class); if (annotation != null) { Method[] methods = type.getMethods(); processControllerMethods(methods, methodsCount); } } Integer allMethodCount = 0; for (Entry<RequestMethod, Integer> methodCount : methodsCount.entrySet()) { LOGGER.info("Http Method - {} : {}", methodCount.getKey(), methodCount.getValue()); allMethodCount += methodCount.getValue(); } LOGGER.info("All methods count: {}", allMethodCount); beanFactory.registerSingleton("httpMethodsCount", allMethodCount); beanFactory.registerSingleton("httpMethods", methodsCount); }  @Override void postProcessBeanFactory(final ConfigurableListableBeanFactory beanFactory);  }
@Test public void testpostProcessBeanFactory() throws Exception { String[] beanDefinitionNames = {"bean1", "bean2"}; when(beanFactory.getBeanDefinitionNames()).thenReturn(beanDefinitionNames); when(beanFactory.getType("bean1")).thenAnswer(new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocationOnMock) throws Throwable { return DepartmentController.class; } }); when(beanFactory.getType("bean2")).thenAnswer(new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocationOnMock) throws Throwable { return DepartmentType.class; } }); unit.postProcessBeanFactory(beanFactory); verify(beanFactory).getBeanDefinitionNames(); }