/** * Scan beans in the ApplicationContext, detect and register handler methods. * @see #getCandidateBeanNames() * @see #processCandidateBean * @see #handlerMethodsInitialized */ protected void initHandlerMethods() { for (String beanName : getCandidateBeanNames()) { if (!beanName.startsWith(SCOPED_TARGET_NAME_PREFIX)) { processCandidateBean(beanName); } } handlerMethodsInitialized(getHandlerMethods()); }
/** * Scan beans in the ApplicationContext, detect and register handler methods. * @see #getCandidateBeanNames() * @see #processCandidateBean * @see #handlerMethodsInitialized */ protected void initHandlerMethods() { for (String beanName : getCandidateBeanNames()) { if (!beanName.startsWith(SCOPED_TARGET_NAME_PREFIX)) { processCandidateBean(beanName); } } handlerMethodsInitialized(getHandlerMethods()); }
@Test public void detectHandlerMethodsInAncestorContexts() { StaticApplicationContext cxt = new StaticApplicationContext(); cxt.registerSingleton("myHandler", MyHandler.class); AbstractHandlerMethodMapping<String> mapping1 = new MyHandlerMethodMapping(); mapping1.setApplicationContext(new StaticApplicationContext(cxt)); mapping1.afterPropertiesSet(); assertEquals(0, mapping1.getHandlerMethods().size()); AbstractHandlerMethodMapping<String> mapping2 = new MyHandlerMethodMapping(); mapping2.setDetectHandlerMethodsInAncestorContexts(true); mapping2.setApplicationContext(new StaticApplicationContext(cxt)); mapping2.afterPropertiesSet(); assertEquals(2, mapping2.getHandlerMethods().size()); }
Map<String, AbstractHandlerMethodMapping> map = WebApplicationContextUtils.getWebApplicationContext(servletContext).getBeansOfType(AbstractHandlerMethodMapping.class); Iterator<AbstractHandlerMethodMapping> iter = map.values().iterator(); while (iter.hasNext()) { AbstractHandlerMethodMapping ahmb = iter.next(); Iterator<Object> urls = ahmb.getHandlerMethods().keySet().iterator(); while (urls.hasNext()) { Object url = urls.next(); logger.error("URL mapped: " + url); } }
private List<String> getAllRequestMappingInfo() { AbstractHandlerMethodMapping<RequestMappingInfo> objHandlerMethodMapping = (AbstractHandlerMethodMapping<RequestMappingInfo>)applicationContext.getBean("requestMappingHandlerMapping"); Map<RequestMappingInfo, HandlerMethod> mapRet = objHandlerMethodMapping.getHandlerMethods(); List<String> res = new ArrayList<String>(); for (Map.Entry<RequestMappingInfo, HandlerMethod> entry : mapRet.entrySet()) { String uri = entry.getKey().toString().replace("{", "").replace("[", "").replace("}","").replace("]",""); String []temp = uri.split(","); res.add(temp[0]); } return res; } }
@SuppressWarnings("rawtypes") private void extractMethodMappings(ApplicationContext applicationContext, Map<String, Object> result) { if (applicationContext != null) { for (Entry<String, AbstractHandlerMethodMapping> bean : applicationContext .getBeansOfType(AbstractHandlerMethodMapping.class).entrySet()) { @SuppressWarnings("unchecked") Map<?, HandlerMethod> methods = bean.getValue().getHandlerMethods(); for (Entry<?, HandlerMethod> method : methods.entrySet()) { Map<String, String> map = new LinkedHashMap<String, String>(); map.put("bean", bean.getKey()); map.put("method", method.getValue().toString()); result.put(method.getKey().toString(), map); } } } }
@SuppressWarnings("rawtypes") private void extractMethodMappings(ApplicationContext applicationContext, Map<String, Object> result) { if (applicationContext != null) { for (Entry<String, AbstractHandlerMethodMapping> bean : applicationContext .getBeansOfType(AbstractHandlerMethodMapping.class).entrySet()) { AbstractHandlerMethodMapping methodMapping = bean.getValue(); if (methodMapping instanceof AbstractWebMvcEndpointHandlerMapping || methodMapping instanceof ControllerEndpointHandlerMapping) { @SuppressWarnings("unchecked") Map<?, HandlerMethod> methods = bean.getValue().getHandlerMethods(); for (Entry<?, HandlerMethod> method : methods.entrySet()) { Map<String, String> map = new LinkedHashMap<String, String>(); map.put("bean", bean.getKey()); map.put("method", method.getValue().toString()); result.put(method.getKey().toString(), map); } } } } }
Table table = new Table( handlerEntry.getKey() + " - " + handlerEntry.getValue().getClass().getName() ); Map<RequestMappingInfo, HandlerMethod> mappings = handlerEntry.getValue().getHandlerMethods();
if (StringUtils.isEmpty(bodyString) || JSONType.getJSONType(bodyString).equals(JSONType.JSON_TYPE_ERROR)) { this.body = new byte[0]; Collection<RequestMappingInfo> mappings = objHandlerMethodMapping.getHandlerMethods().keySet(); mappings.forEach(mapping -> { RequestMappingInfo requestMappingInfo = mapping.getMatchingCondition(request);
handlerMethodsInitialized(getHandlerMethods());