當前位置: 首頁>>代碼示例>>Java>>正文


Java HandlerMethodArgumentResolver類代碼示例

本文整理匯總了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);
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:17,代碼來源:WxBuildinMvcConfiguration.java

示例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();
                }
            });
        }
    };
}
 
開發者ID:hs-web,項目名稱:hsweb-framework,代碼行數:22,代碼來源:HswebAutoConfiguration.java

示例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;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:ExceptionHandlerExceptionResolver.java

示例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());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:RequestMappingHandlerAdapterTests.java

示例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);
}
 
開發者ID:shilongdai,項目名稱:bookManager,代碼行數:20,代碼來源:ServletApplicationContextConfig.java

示例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);
			}
		}

	};
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-function,代碼行數:24,代碼來源:ReactorAutoConfiguration.java

示例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);
    }
}
 
開發者ID:hosuaby,項目名稱:example-restful-project,代碼行數:23,代碼來源:WebMvcConfig.java

示例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;
}
 
開發者ID:thunderbird,項目名稱:pungwecms,代碼行數:17,代碼來源:FormHandlerMappingPostProcessor.java

示例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));
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:25,代碼來源:RequestMappingHandlerAdapterIntegrationTests.java

示例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());
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:19,代碼來源:RequestMappingHandlerAdapterTests.java

示例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();
  }
}
 
開發者ID:tunguski,項目名稱:matsuo-core,代碼行數:18,代碼來源:MvcConfig.java

示例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"));
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-aws,代碼行數:17,代碼來源:SnsConfigurationTest.java

示例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);
       }
}
 
開發者ID:tkaczmarzyk,項目名稱:specification-arg-resolver,代碼行數:20,代碼來源:JoinsSpecificationResolver.java


注:本文中的org.springframework.web.method.support.HandlerMethodArgumentResolver類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。