本文整理匯總了Java中org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter類的典型用法代碼示例。如果您正苦於以下問題:Java RequestMappingHandlerAdapter類的具體用法?Java RequestMappingHandlerAdapter怎麽用?Java RequestMappingHandlerAdapter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
RequestMappingHandlerAdapter類屬於org.springframework.web.servlet.mvc.method.annotation包,在下文中一共展示了RequestMappingHandlerAdapter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testCustomConversionService
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的package包/類
@Test(expected = TypeMismatchException.class)
public void testCustomConversionService() throws Exception {
loadBeanDefinitions("mvc-config-custom-conversion-service.xml", 14);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
mapping.setDefaultHandler(handlerMethod);
// default web binding initializer behavior test
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
request.setRequestURI("/accounts/12345");
request.addParameter("date", "2009-10-31");
MockHttpServletResponse response = new MockHttpServletResponse();
HandlerExecutionChain chain = mapping.getHandler(request);
assertEquals(1, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
ConversionServiceExposingInterceptor interceptor = (ConversionServiceExposingInterceptor) chain.getInterceptors()[0];
interceptor.preHandle(request, response, handler);
assertSame(appContext.getBean("conversionService"), request.getAttribute(ConversionService.class.getName()));
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
adapter.handle(request, response, handlerMethod);
}
示例2: afterPropertiesSet
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的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);
}
示例3: doTestCustomValidator
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的package包/類
private void doTestCustomValidator(String xml) throws Exception {
loadBeanDefinitions(xml, 14);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
assertFalse(mapping.getUrlPathHelper().shouldRemoveSemicolonContent());
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
assertEquals(true, new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"));
// default web binding initializer behavior test
MockHttpServletRequest request = new MockHttpServletRequest();
request.addParameter("date", "2009-10-31");
MockHttpServletResponse response = new MockHttpServletResponse();
adapter.handle(request, response, handlerMethod);
assertTrue(appContext.getBean(TestValidator.class).validatorInvoked);
assertFalse(handler.recordedValidationError);
}
示例4: testAsyncSupportOptions
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的package包/類
@Test
public void testAsyncSupportOptions() throws Exception {
loadBeanDefinitions("mvc-config-async-support.xml", 15);
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertNotNull(adapter);
DirectFieldAccessor fieldAccessor = new DirectFieldAccessor(adapter);
assertEquals(ConcurrentTaskExecutor.class, fieldAccessor.getPropertyValue("taskExecutor").getClass());
assertEquals(2500L, fieldAccessor.getPropertyValue("asyncRequestTimeout"));
CallableProcessingInterceptor[] callableInterceptors =
(CallableProcessingInterceptor[]) fieldAccessor.getPropertyValue("callableInterceptors");
assertEquals(1, callableInterceptors.length);
DeferredResultProcessingInterceptor[] deferredResultInterceptors =
(DeferredResultProcessingInterceptor[]) fieldAccessor.getPropertyValue("deferredResultInterceptors");
assertEquals(1, deferredResultInterceptors.length);
}
示例5: requestMappingHandlerAdapter
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的package包/類
@Test
public void requestMappingHandlerAdapter() throws Exception {
delegatingConfig.setConfigurers(Arrays.asList(webMvcConfigurer));
RequestMappingHandlerAdapter adapter = delegatingConfig.requestMappingHandlerAdapter();
ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
ConversionService initializerConversionService = initializer.getConversionService();
assertTrue(initializer.getValidator() instanceof LocalValidatorFactoryBean);
verify(webMvcConfigurer).configureMessageConverters(converters.capture());
verify(webMvcConfigurer).configureContentNegotiation(contentNegotiationConfigurer.capture());
verify(webMvcConfigurer).addFormatters(conversionService.capture());
verify(webMvcConfigurer).addArgumentResolvers(resolvers.capture());
verify(webMvcConfigurer).addReturnValueHandlers(handlers.capture());
verify(webMvcConfigurer).configureAsyncSupport(asyncConfigurer.capture());
assertSame(conversionService.getValue(), initializerConversionService);
assertEquals(0, resolvers.getValue().size());
assertEquals(0, handlers.getValue().size());
assertEquals(converters.getValue(), adapter.getMessageConverters());
assertNotNull(asyncConfigurer);
}
示例6: testArgumentResolvers
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的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: rebuildMessageConverter
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的package包/類
private void rebuildMessageConverter(RequestMappingHandlerAdapter adapter) {
List<HttpMessageConverter<?>> messageConverters = adapter.getMessageConverters();
if (!CollectionUtils.isEmpty(messageConverters)) {
for (HttpMessageConverter<?> messageConverter : messageConverters) {
if (messageConverter instanceof MappingJackson2HttpMessageConverter) {
rebuildJacksonV2((MappingJackson2HttpMessageConverter) messageConverter);
}
// if (messageConverter instanceof MappingJacksonHttpMessageConverter) {
// rebuildJacksonV1((MappingJacksonHttpMessageConverter) messageConverter);
// }
}
}
/**
* 處理form表單
* form表單通過get方法請求,controller裏邊的方法中隻需設置一個接收的對象即可.
*/
adapter.getMessageConverters().add(new FormHttpMessageConverter());
}
示例8: findConverter
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private HttpMessageConverter<Object> findConverter(
Class<? extends HttpMessageConverter<?>> selectedConverterType,
MediaType mediaType) {
HttpMessageConverter<Object> cached = (HttpMessageConverter<Object>) this.converterCache
.get(mediaType);
if (cached != null) {
return cached;
}
for (RequestMappingHandlerAdapter handlerAdapter : this.handlerAdapters) {
for (HttpMessageConverter<?> converter : handlerAdapter
.getMessageConverters()) {
if (selectedConverterType.isAssignableFrom(converter.getClass())
&& converter.canWrite(EndpointResource.class, mediaType)) {
this.converterCache.put(mediaType, converter);
return (HttpMessageConverter<Object>) converter;
}
}
}
return null;
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:22,代碼來源:EndpointWebMvcHypermediaManagementContextConfiguration.java
示例9: customizedSupportedMediaTypes
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的package包/類
@PostConstruct
public void customizedSupportedMediaTypes() {
if (this.beanFactory instanceof ListableBeanFactory) {
Map<String, RequestMappingHandlerAdapter> handlerAdapters = ((ListableBeanFactory) this.beanFactory)
.getBeansOfType(RequestMappingHandlerAdapter.class);
for (Entry<String, RequestMappingHandlerAdapter> entry : handlerAdapters
.entrySet()) {
RequestMappingHandlerAdapter handlerAdapter = entry.getValue();
for (HttpMessageConverter<?> converter : handlerAdapter
.getMessageConverters()) {
if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
((TypeConstrainedMappingJackson2HttpMessageConverter) converter)
.setSupportedMediaTypes(
Arrays.asList(MediaTypes.HAL_JSON,
MediaType.APPLICATION_JSON));
}
}
}
}
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:22,代碼來源:HypermediaHttpMessageConverterConfiguration.java
示例10: customizationOfSupportedMediaTypesCanBeDisabled
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的package包/類
@Test
public void customizationOfSupportedMediaTypesCanBeDisabled() {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(BaseConfig.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.hateoas.use-hal-as-default-json-media-type:false");
this.context.refresh();
RequestMappingHandlerAdapter handlerAdapter = this.context
.getBean(RequestMappingHandlerAdapter.class);
for (HttpMessageConverter<?> converter : handlerAdapter.getMessageConverters()) {
if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
assertThat(converter.getSupportedMediaTypes())
.containsExactly(MediaTypes.HAL_JSON);
}
}
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:18,代碼來源:HypermediaAutoConfigurationTests.java
示例11: webMvcRegistrations
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的package包/類
@Bean
public WebMvcRegistrations webMvcRegistrations() {
return new WebMvcRegistrationsAdapter() {
@Override
public RequestMappingHandlerMapping getRequestMappingHandlerMapping() {
DefaultRequestMappingHandlerMapping mapping = new DefaultRequestMappingHandlerMapping();
mapping.setControllerPostfix("Controller");
mapping.setExcludePatterns(new String[]{
"/js/**",
"/css/**",
"/imgs/**"
});
return mapping;
}
@Override
public RequestMappingHandlerAdapter getRequestMappingHandlerAdapter() {
DefaultRequestMappingHandlerAdapter adapter = new DefaultRequestMappingHandlerAdapter();
adapter.setAutoView(true);
return adapter;
}
};
}
示例12: findConverter
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private HttpMessageConverter<Object> findConverter(
Class<? extends HttpMessageConverter<?>> selectedConverterType,
MediaType mediaType) {
if (this.converterCache.containsKey(mediaType)) {
return (HttpMessageConverter<Object>) this.converterCache.get(mediaType);
}
for (RequestMappingHandlerAdapter handlerAdapter : this.handlerAdapters) {
for (HttpMessageConverter<?> converter : handlerAdapter
.getMessageConverters()) {
if (selectedConverterType.isAssignableFrom(converter.getClass())
&& converter.canWrite(EndpointResource.class, mediaType)) {
this.converterCache.put(mediaType, converter);
return (HttpMessageConverter<Object>) converter;
}
}
}
return null;
}
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:20,代碼來源:EndpointWebMvcHypermediaManagementContextConfiguration.java
示例13: fluxRequestMappingHandlerAdapterProcessor
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的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);
}
}
};
}
示例14: onApplicationEvent
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的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);
}
}
示例15: customizationOfSupportedMediaTypesCanBeDisabled
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; //導入依賴的package包/類
@Test
public void customizationOfSupportedMediaTypesCanBeDisabled() {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(BaseConfig.class);
EnvironmentTestUtils.addEnvironment(this.context,
"spring.hateoas.use-hal-as-default-json-media-type:false");
this.context.refresh();
RequestMappingHandlerAdapter handlerAdapter = this.context
.getBean(RequestMappingHandlerAdapter.class);
for (HttpMessageConverter<?> converter : handlerAdapter.getMessageConverters()) {
if (converter instanceof TypeConstrainedMappingJackson2HttpMessageConverter) {
assertThat(converter.getSupportedMediaTypes(),
contains(MediaTypes.HAL_JSON));
}
}
}