当前位置: 首页>>代码示例>>Java>>正文


Java HandlerMethodReturnValueHandler类代码示例

本文整理汇总了Java中org.springframework.web.method.support.HandlerMethodReturnValueHandler的典型用法代码示例。如果您正苦于以下问题:Java HandlerMethodReturnValueHandler类的具体用法?Java HandlerMethodReturnValueHandler怎么用?Java HandlerMethodReturnValueHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HandlerMethodReturnValueHandler类属于org.springframework.web.method.support包,在下文中一共展示了HandlerMethodReturnValueHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: afterPropertiesSet

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的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: setAlwaysUseRedirectAttributes

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的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

示例3: fluxRequestMappingHandlerAdapterProcessor

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的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

示例4: onApplicationEvent

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的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

示例5: setAlwaysUseRedirectAttributes

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的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

示例6: rxJavaWebMvcConfiguration

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的package包/类
@Bean
public WebMvcConfigurer rxJavaWebMvcConfiguration(List<AsyncHandlerMethodReturnValueHandler> handlers) {
    return new WebMvcConfigurerAdapter() {
        @Override
        public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
            if (handlers != null) {
                returnValueHandlers.addAll(handlers);
            }
        }
    };
}
 
开发者ID:quebic-source,项目名称:microservices-sample-project,代码行数:12,代码来源:AsyncConfig.java

示例7: install

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的package包/类
public GuavaLFReturnValueHandler install(RequestMappingHandlerAdapter requestMappingHandlerAdapter) {
    final List<HandlerMethodReturnValueHandler> originalHandlers = new ArrayList<>(
            requestMappingHandlerAdapter.getReturnValueHandlers());

    final int deferredPos = indexOfType(originalHandlers, DeferredResultMethodReturnValueHandler.class);
    // Add our handler directly after the deferred handler.
    originalHandlers.add(deferredPos + 1, this);

    requestMappingHandlerAdapter.setReturnValueHandlers(originalHandlers);

    return this;
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:13,代码来源:GuavaLFReturnValueHandler.java

示例8: indexOfType

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的package包/类
private int indexOfType(final List<HandlerMethodReturnValueHandler> originalHandlers, Class<?> handlerClass) {
    for (int i = 0; i < originalHandlers.size(); i++) {
        final HandlerMethodReturnValueHandler valueHandler = originalHandlers.get(i);
        if (handlerClass.isAssignableFrom(valueHandler.getClass())) {
            return i;
        }
    }
    return -1;
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:10,代码来源:GuavaLFReturnValueHandler.java

示例9: handlerIsAfterDeferredResultMethodReturnValueHandler

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的package包/类
@Test
public void handlerIsAfterDeferredResultMethodReturnValueHandler() {
    List<HandlerMethodReturnValueHandler> handlers = requestMappingHandlerAdapter.getReturnValueHandlers();
    int lfHandlerIndex = indexOfType(handlers, GuavaLFReturnValueHandler.class);
    int drHandlerIndex = indexOfType(handlers, DeferredResultMethodReturnValueHandler.class);

    assertThat(lfHandlerIndex).isGreaterThan(drHandlerIndex);
}
 
开发者ID:salesforce,项目名称:grpc-java-contrib,代码行数:9,代码来源:GuavaLFReturnValueHandlerTest.java

示例10: setReturnValueHandlers

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的package包/类
/**
 * Configure the complete list of supported return value types thus
 * overriding handlers that would otherwise be configured by default.
 */
public void setReturnValueHandlers(List<HandlerMethodReturnValueHandler> returnValueHandlers) {
	if (returnValueHandlers == null) {
		this.returnValueHandlers = null;
	}
	else {
		this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite();
		this.returnValueHandlers.addHandlers(returnValueHandlers);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:ExceptionHandlerExceptionResolver.java

示例11: afterPropertiesSet

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的package包/类
@Override
public void afterPropertiesSet() {
	// Do this first, it may add ResponseBodyAdvice beans
	initExceptionHandlerAdviceCache();

	if (this.argumentResolvers == null) {
		List<HandlerMethodArgumentResolver> resolvers = getDefaultArgumentResolvers();
		this.argumentResolvers = new HandlerMethodArgumentResolverComposite().addResolvers(resolvers);
	}
	if (this.returnValueHandlers == null) {
		List<HandlerMethodReturnValueHandler> handlers = getDefaultReturnValueHandlers();
		this.returnValueHandlers = new HandlerMethodReturnValueHandlerComposite().addHandlers(handlers);
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:15,代码来源:ExceptionHandlerExceptionResolver.java

示例12: getDefaultReturnValueHandlers

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的package包/类
/**
 * Return the list of return value handlers to use including built-in and
 * custom handlers provided via {@link #setReturnValueHandlers}.
 */
protected List<HandlerMethodReturnValueHandler> getDefaultReturnValueHandlers() {
	List<HandlerMethodReturnValueHandler> handlers = new ArrayList<HandlerMethodReturnValueHandler>();

	// Single-purpose return value types
	handlers.add(new ModelAndViewMethodReturnValueHandler());
	handlers.add(new ModelMethodProcessor());
	handlers.add(new ViewMethodReturnValueHandler());
	handlers.add(new HttpEntityMethodProcessor(
			getMessageConverters(), this.contentNegotiationManager, this.responseBodyAdvice));

	// Annotation-based return value types
	handlers.add(new ModelAttributeMethodProcessor(false));
	handlers.add(new RequestResponseBodyMethodProcessor(
			getMessageConverters(), this.contentNegotiationManager, this.responseBodyAdvice));

	// Multi-purpose return value types
	handlers.add(new ViewNameMethodReturnValueHandler());
	handlers.add(new MapMethodProcessor());

	// Custom return value types
	if (getCustomReturnValueHandlers() != null) {
		handlers.addAll(getCustomReturnValueHandlers());
	}

	// Catch-all
	handlers.add(new ModelAttributeMethodProcessor(true));

	return handlers;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:ExceptionHandlerExceptionResolver.java

示例13: requestMappingHandlerAdapter

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的package包/类
/**
 * Returns a {@link RequestMappingHandlerAdapter} for processing requests
 * through annotated controller methods. Consider overriding one of these
 * other more fine-grained methods:
 * <ul>
 * <li>{@link #addArgumentResolvers} for adding custom argument resolvers.
 * <li>{@link #addReturnValueHandlers} for adding custom return value handlers.
 * <li>{@link #configureMessageConverters} for adding custom message converters.
 * </ul>
 */
@Bean
public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
	List<HandlerMethodArgumentResolver> argumentResolvers = new ArrayList<HandlerMethodArgumentResolver>();
	addArgumentResolvers(argumentResolvers);

	List<HandlerMethodReturnValueHandler> returnValueHandlers = new ArrayList<HandlerMethodReturnValueHandler>();
	addReturnValueHandlers(returnValueHandlers);

	RequestMappingHandlerAdapter adapter = new RequestMappingHandlerAdapter();
	adapter.setContentNegotiationManager(mvcContentNegotiationManager());
	adapter.setMessageConverters(getMessageConverters());
	adapter.setWebBindingInitializer(getConfigurableWebBindingInitializer());
	adapter.setCustomArgumentResolvers(argumentResolvers);
	adapter.setCustomReturnValueHandlers(returnValueHandlers);

	if (jackson2Present) {
		List<RequestBodyAdvice> requestBodyAdvices = new ArrayList<RequestBodyAdvice>();
		requestBodyAdvices.add(new JsonViewRequestBodyAdvice());
		adapter.setRequestBodyAdvice(requestBodyAdvices);

		List<ResponseBodyAdvice<?>> responseBodyAdvices = new ArrayList<ResponseBodyAdvice<?>>();
		responseBodyAdvices.add(new JsonViewResponseBodyAdvice());
		adapter.setResponseBodyAdvice(responseBodyAdvices);
	}

	AsyncSupportConfigurer configurer = new AsyncSupportConfigurer();
	configureAsyncSupport(configurer);

	if (configurer.getTaskExecutor() != null) {
		adapter.setTaskExecutor(configurer.getTaskExecutor());
	}
	if (configurer.getTimeout() != null) {
		adapter.setAsyncRequestTimeout(configurer.getTimeout());
	}
	adapter.setCallableInterceptors(configurer.getCallableInterceptors());
	adapter.setDeferredResultInterceptors(configurer.getDeferredResultInterceptors());

	return adapter;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:50,代码来源:WebMvcConfigurationSupport.java

示例14: setCustomReturnValueHandlers

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的package包/类
@Test
public void setCustomReturnValueHandlers() {
	HandlerMethodReturnValueHandler handler = new ViewNameMethodReturnValueHandler();
	this.resolver.setCustomReturnValueHandlers(Arrays.asList(handler));
	this.resolver.afterPropertiesSet();

	assertTrue(this.resolver.getReturnValueHandlers().getHandlers().contains(handler));
	assertMethodProcessorCount(RESOLVER_COUNT, HANDLER_COUNT + 1);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:ExceptionHandlerExceptionResolverTests.java

示例15: setReturnValueHandlers

import org.springframework.web.method.support.HandlerMethodReturnValueHandler; //导入依赖的package包/类
@Test
public void setReturnValueHandlers() {
	HandlerMethodReturnValueHandler handler = new ModelMethodProcessor();
	this.resolver.setReturnValueHandlers(Arrays.asList(handler));
	this.resolver.afterPropertiesSet();

	assertMethodProcessorCount(RESOLVER_COUNT, 1);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:9,代码来源:ExceptionHandlerExceptionResolverTests.java


注:本文中的org.springframework.web.method.support.HandlerMethodReturnValueHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。