本文整理汇总了Java中org.springframework.web.method.support.HandlerMethodArgumentResolver类的典型用法代码示例。如果您正苦于以下问题:Java HandlerMethodArgumentResolver类的具体用法?Java HandlerMethodArgumentResolver怎么用?Java HandlerMethodArgumentResolver使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HandlerMethodArgumentResolver类属于org.springframework.web.method.support包,在下文中一共展示了HandlerMethodArgumentResolver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterPropertiesSet
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
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)));
}
returnValueHandlers.add(beanFactory.getBean(WxAsyncMessageReturnValueHandler.class));
argumentResolvers.addAll(requestMappingHandlerAdapter.getArgumentResolvers());
returnValueHandlers.addAll(requestMappingHandlerAdapter.getReturnValueHandlers());
requestMappingHandlerAdapter.setArgumentResolvers(argumentResolvers);
requestMappingHandlerAdapter.setReturnValueHandlers(returnValueHandlers);
}
示例2: webMvcConfigurer
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@Bean
public WebMvcConfigurer webMvcConfigurer(List<HandlerMethodArgumentResolver> handlerMethodArgumentResolvers) {
return new WebMvcConfigurerAdapter() {
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
super.addArgumentResolvers(argumentResolvers);
argumentResolvers.addAll(handlerMethodArgumentResolvers);
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new HandlerInterceptorAdapter() {
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
//clear thread local
ThreadLocalUtils.clear();
}
});
}
};
}
示例3: getDefaultArgumentResolvers
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
/**
* Return the list of argument resolvers to use including built-in resolvers
* and custom resolvers provided via {@link #setCustomArgumentResolvers}.
*/
protected List<HandlerMethodArgumentResolver> getDefaultArgumentResolvers() {
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<HandlerMethodArgumentResolver>();
// Type-based argument resolution
resolvers.add(new ServletRequestMethodArgumentResolver());
resolvers.add(new ServletResponseMethodArgumentResolver());
resolvers.add(new ModelMethodProcessor());
// Custom arguments
if (getCustomArgumentResolvers() != null) {
resolvers.addAll(getCustomArgumentResolvers());
}
return resolvers;
}
示例4: setup
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@Before
public void setup() throws Exception {
ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
bindingInitializer.setValidator(new StubValidator());
List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<HandlerMethodArgumentResolver>();
customResolvers.add(new ServletWebArgumentResolverAdapter(new ColorArgumentResolver()));
GenericWebApplicationContext context = new GenericWebApplicationContext();
context.refresh();
handlerAdapter = new RequestMappingHandlerAdapter();
handlerAdapter.setWebBindingInitializer(bindingInitializer);
handlerAdapter.setCustomArgumentResolvers(customResolvers);
handlerAdapter.setApplicationContext(context);
handlerAdapter.setBeanFactory(context.getBeanFactory());
handlerAdapter.afterPropertiesSet();
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
request.setMethod("POST");
// Expose request to the current thread (for SpEL expressions)
RequestContextHolder.setRequestAttributes(new ServletWebRequest(request));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:RequestMappingHandlerAdapterIntegrationTests.java
示例5: setAlwaysUseRedirectAttributes
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@Test
public void setAlwaysUseRedirectAttributes() throws Exception {
HandlerMethodArgumentResolver redirectAttributesResolver = new RedirectAttributesMethodArgumentResolver();
HandlerMethodArgumentResolver modelResolver = new ModelMethodProcessor();
HandlerMethodReturnValueHandler viewHandler = new ViewNameMethodReturnValueHandler();
this.handlerAdapter.setArgumentResolvers(Arrays.asList(redirectAttributesResolver, modelResolver));
this.handlerAdapter.setReturnValueHandlers(Collections.singletonList(viewHandler));
this.handlerAdapter.setIgnoreDefaultModelOnRedirect(true);
this.handlerAdapter.afterPropertiesSet();
this.request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
HandlerMethod handlerMethod = handlerMethod(new RedirectAttributeController(), "handle", Model.class);
ModelAndView mav = this.handlerAdapter.handle(request, response, handlerMethod);
assertTrue("Without RedirectAttributes arg, model should be empty", mav.getModel().isEmpty());
}
示例6: testArgumentResolvers
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testArgumentResolvers() {
loadBeanDefinitions("mvc-config-argument-resolvers.xml");
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
Object value = new DirectFieldAccessor(adapter).getPropertyValue("customArgumentResolvers");
assertNotNull(value);
assertTrue(value instanceof List);
List<HandlerMethodArgumentResolver> resolvers = (List<HandlerMethodArgumentResolver>) value;
assertEquals(3, resolvers.size());
assertTrue(resolvers.get(0) instanceof ServletWebArgumentResolverAdapter);
assertTrue(resolvers.get(1) instanceof TestHandlerMethodArgumentResolver);
assertTrue(resolvers.get(2) instanceof TestHandlerMethodArgumentResolver);
assertNotSame(resolvers.get(1), resolvers.get(2));
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:AnnotationDrivenBeanDefinitionParserTests.java
示例7: addArgumentResolvers
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
Sort defaultSort = new Sort(new Sort.Order(Sort.Direction.ASC, "id"));
Pageable defaultPage = new PageRequest(0, 10, defaultSort);
SortHandlerMethodArgumentResolver sortHandlerMethodArgumentResolver = new SortHandlerMethodArgumentResolver();
sortHandlerMethodArgumentResolver.setSortParameter("sort");
sortHandlerMethodArgumentResolver.setFallbackSort(defaultSort);
PageableHandlerMethodArgumentResolver pageableResolver = new PageableHandlerMethodArgumentResolver();
pageableResolver.setMaxPageSize(100);
pageableResolver.setOneIndexedParameters(false);
pageableResolver.setPageParameterName("page");
pageableResolver.setSizeParameterName("size");
pageableResolver.setFallbackPageable(defaultPage);
argumentResolvers.add(sortHandlerMethodArgumentResolver);
argumentResolvers.add(pageableResolver);
}
示例8: fluxRequestMappingHandlerAdapterProcessor
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@Bean
public SmartInitializingSingleton fluxRequestMappingHandlerAdapterProcessor(
RequestMappingHandlerAdapter adapter,
FluxHandlerMethodArgumentResolver resolver) {
return new SmartInitializingSingleton() {
@Override
public void afterSingletonsInstantiated() {
List<HandlerMethodArgumentResolver> resolvers = new ArrayList<>(
adapter.getArgumentResolvers());
resolvers.add(0, resolver);
adapter.setArgumentResolvers(resolvers);
if (!ClassUtils.isPresent("org.springframework.core.ReactiveAdapter",
null)) {
List<HandlerMethodReturnValueHandler> handlers = new ArrayList<>(
adapter.getReturnValueHandlers());
handlers.add(0, context.getBean(FluxReturnValueHandler.class));
adapter.setReturnValueHandlers(handlers);
}
}
};
}
示例9: onApplicationEvent
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@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);
}
}
示例10: postProcessAfterInitialization
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (bean instanceof RequestMappingHandlerAdapter) {
RequestMappingHandlerAdapter adapter = (RequestMappingHandlerAdapter) bean;
List<HandlerMethodArgumentResolver> resolvers = new LinkedList<>();
resolvers.addAll(adapter.getArgumentResolvers());
resolvers.replaceAll(handlerMethodArgumentResolver -> {
if (handlerMethodArgumentResolver instanceof ServletModelAttributeMethodProcessor) {
return new FormModelAttributeMethodProcessor(false);
}
return handlerMethodArgumentResolver;
});
adapter.setArgumentResolvers(resolvers);
}
return bean;
}
示例11: setup
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@Before
public void setup() throws Exception {
ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
bindingInitializer.setValidator(new StubValidator());
List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<HandlerMethodArgumentResolver>();
customResolvers.add(new ServletWebArgumentResolverAdapter(new ColorArgumentResolver()));
GenericWebApplicationContext context = new GenericWebApplicationContext();
context.refresh();
handlerAdapter = new RequestMappingHandlerAdapter();
handlerAdapter.setWebBindingInitializer(bindingInitializer);
handlerAdapter.setCustomArgumentResolvers(customResolvers);
handlerAdapter.setApplicationContext(context);
handlerAdapter.setBeanFactory(context.getBeanFactory());
handlerAdapter.afterPropertiesSet();
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
// Expose request to the current thread (for SpEL expressions)
RequestContextHolder.setRequestAttributes(new ServletWebRequest(request));
}
示例12: setAlwaysUseRedirectAttributes
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@Test
public void setAlwaysUseRedirectAttributes() throws Exception {
HandlerMethodArgumentResolver redirectAttributesResolver = new RedirectAttributesMethodArgumentResolver();
HandlerMethodArgumentResolver modelResolver = new ModelMethodProcessor();
HandlerMethodReturnValueHandler viewHandler = new ViewNameMethodReturnValueHandler();
this.handlerAdapter.setArgumentResolvers(Arrays.asList(redirectAttributesResolver, modelResolver));
this.handlerAdapter.setReturnValueHandlers(Arrays.asList(viewHandler));
this.handlerAdapter.setIgnoreDefaultModelOnRedirect(true);
this.handlerAdapter.afterPropertiesSet();
this.request.setAttribute(DispatcherServlet.OUTPUT_FLASH_MAP_ATTRIBUTE, new FlashMap());
HandlerMethod handlerMethod = handlerMethod(new RedirectAttributeController(), "handle", Model.class);
ModelAndView mav = this.handlerAdapter.handle(request, response, handlerMethod);
assertTrue("Without RedirectAttributes arg, model should be empty", mav.getModel().isEmpty());
}
示例13: onApplicationEvent
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
RequestMappingHandlerAdapter adapter = event.getApplicationContext().getBean(RequestMappingHandlerAdapter.class);
try {
FacadeBuilderHandlerMethodArgumentResolver facadeBuilderHandlerMethodArgumentResolver =
event.getApplicationContext().getBean(FacadeBuilderHandlerMethodArgumentResolver.class);
List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<>(adapter.getArgumentResolvers());
List<HandlerMethodArgumentResolver> customResolvers = adapter.getCustomArgumentResolvers();
argumentResolvers.remove(facadeBuilderHandlerMethodArgumentResolver);
argumentResolvers.add(0, facadeBuilderHandlerMethodArgumentResolver);
adapter.setArgumentResolvers(argumentResolvers);
} catch (BeansException e) {
//e.printStackTrace();
}
}
示例14: enableSns_withMinimalConfig_shouldConfigureACompositeArgumentResolver
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@Test
public void enableSns_withMinimalConfig_shouldConfigureACompositeArgumentResolver() throws Exception {
// Arrange & Act
this.webApplicationContext.register(MinimalSnsConfiguration.class);
this.webApplicationContext.refresh();
RequestMappingHandlerAdapter requestMappingHandlerAdapter = this.webApplicationContext.getBean(RequestMappingHandlerAdapter.class);
// Assert
assertEquals(1, requestMappingHandlerAdapter.getCustomArgumentResolvers().size());
HandlerMethodArgumentResolver argumentResolver = requestMappingHandlerAdapter.getCustomArgumentResolvers().get(0);
assertTrue(HandlerMethodArgumentResolverComposite.class.isInstance(argumentResolver));
HandlerMethodArgumentResolverComposite compositeArgumentResolver = (HandlerMethodArgumentResolverComposite) argumentResolver;
assertEquals(3, compositeArgumentResolver.getResolvers().size());
assertNotNull(ReflectionTestUtils.getField(getNotificationStatusHandlerMethodArgumentResolver(compositeArgumentResolver.getResolvers()), "amazonSns"));
}
示例15: resolveArgument
import org.springframework.web.method.support.HandlerMethodArgumentResolver; //导入依赖的package包/类
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory,
List<HandlerMethodArgumentResolver> recursiveCallers) throws Exception {
recursiveCallers.add(this);
Specification<Object> joins = resolveJoins(parameter, webRequest);
@SuppressWarnings("unchecked")
Specification<Object> regularSpec = (Specification<Object>) parent.resolveArgument(parameter, mavContainer, webRequest, binderFactory, recursiveCallers);
Specification<Object> spec = regularSpec == null ? joins : new Conjunction<Object>(Arrays.asList(joins, regularSpec));
if (Specification.class == parameter.getParameterType()) {
return spec;
} else {
return EnhancerUtil.wrapWithIfaceImplementation(parameter.getParameterType(), spec);
}
}