Java Code Examples for org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#setArgumentResolvers()
The following examples show how to use
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#setArgumentResolvers() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RaptorHandlerAdapterPostProcessor.java From raptor with Apache License 2.0 | 6 votes |
@Override public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { if (RequestMappingHandlerAdapter.class.isAssignableFrom(ClassUtils.getUserClass(bean))) { RequestMappingHandlerAdapter adapter = (RequestMappingHandlerAdapter) bean; List<Object> advices = getRequestResponseBodyAdviceByReflect(adapter); RaptorHandlerMethodProcessor raptorHandlerMethodProcessor = new RaptorHandlerMethodProcessor(raptorMessageConverter,advices); ArrayList<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>(adapter.getArgumentResolvers()); argumentResolvers.add(0, raptorHandlerMethodProcessor); adapter.setArgumentResolvers(argumentResolvers); ArrayList<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<>(adapter.getReturnValueHandlers()); returnValueHandlers.add(0, raptorHandlerMethodProcessor); adapter.setReturnValueHandlers(returnValueHandlers); } return bean; }
Example 2
Source File: WxMvcConfiguration.java From FastBootWeixin with Apache License 2.0 | 6 votes |
@Override public void afterPropertiesSet() { RequestMappingHandlerAdapter requestMappingHandlerAdapter = this.beanFactory.getBean(RequestMappingHandlerAdapter.class); List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>(); List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<>(); if (beanFactory instanceof ConfigurableBeanFactory) { argumentResolvers.add(new WxArgumentResolver((ConfigurableBeanFactory) beanFactory)); } else { argumentResolvers.add(new WxArgumentResolver(beanFactory.getBean(WxUserManager.class), beanFactory.getBean(WxUserProvider.class))); } // 可以换成@Autowired,Spring内部框架就是这样做的 // returnValueHandlers.add(beanFactory.getBean(WxAsyncMessageReturnValueHandler.class)); // returnValueHandlers.add(beanFactory.getBean(WxSyncMessageReturnValueHandler.class)); returnValueHandlers.add(beanFactory.getBean(WxMappingReturnValueHandler.class)); returnValueHandlers.add(beanFactory.getBean(WxMessageReturnValueHandler.class)); argumentResolvers.addAll(requestMappingHandlerAdapter.getArgumentResolvers()); returnValueHandlers.addAll(requestMappingHandlerAdapter.getReturnValueHandlers()); requestMappingHandlerAdapter.setArgumentResolvers(argumentResolvers); requestMappingHandlerAdapter.setReturnValueHandlers(returnValueHandlers); }
Example 3
Source File: WebMvcConfig.java From example-restful-project with MIT License | 6 votes |
@Override public void onApplicationEvent(ApplicationEvent event) { if (event instanceof ContextRefreshedEvent) { ApplicationContext applicationContext = ((ContextRefreshedEvent) event).getApplicationContext(); RequestMappingHandlerAdapter adapter = applicationContext.getBean(RequestMappingHandlerAdapter.class); TeapotMappingHandler handler = new TeapotMappingHandler( mapper, getMessageConverters()); List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>(); argumentResolvers.add(handler); argumentResolvers.addAll(adapter.getArgumentResolvers()); adapter.setArgumentResolvers(argumentResolvers); List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(); handlers.add(handler); // must be first handlers.addAll(adapter.getReturnValueHandlers()); adapter.setReturnValueHandlers(handlers); } }
Example 4
Source File: CometConfig.java From Milkomeda with MIT License | 5 votes |
@Autowired @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") public void configParamResolve(RequestMappingHandlerAdapter adapter) { List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>(); // 动态添加针对注解 @CometParam 处理的解析器 argumentResolvers.add(new CometParamResolver()); argumentResolvers.addAll(Objects.requireNonNull(adapter.getArgumentResolvers())); adapter.setArgumentResolvers(argumentResolvers); }
Example 5
Source File: CustomArgumentResolversConfig.java From yue-library with Apache License 2.0 | 5 votes |
@Autowired public void prioritizeCustomMethodArgumentHandlers(RequestMappingHandlerAdapter adapter) { List<HandlerMethodArgumentResolver> prioritizeCustomArgumentResolvers = new ArrayList<>(); prioritizeCustomArgumentResolvers.add(new JSONObjectArgumentResolver()); prioritizeCustomArgumentResolvers.addAll(adapter.getArgumentResolvers()); adapter.setArgumentResolvers(prioritizeCustomArgumentResolvers); }