use of org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping in project spring-framework by spring-projects.
the class WebMvcConfigurationSupport method beanNameHandlerMapping.
/**
* Return a {@link BeanNameUrlHandlerMapping} ordered at 2 to map URL
* paths to controller bean names.
*/
@Bean
public BeanNameUrlHandlerMapping beanNameHandlerMapping() {
BeanNameUrlHandlerMapping mapping = new BeanNameUrlHandlerMapping();
mapping.setOrder(2);
mapping.setInterceptors(getInterceptors());
mapping.setCorsConfigurations(getCorsConfigurations());
return mapping;
}
use of org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping in project tutorials by eugenp.
the class HandlerMappingPrioritiesConfig method beanNameUrlHandlerMapping.
@Bean
BeanNameUrlHandlerMapping beanNameUrlHandlerMapping() {
BeanNameUrlHandlerMapping beanNameUrlHandlerMapping = new BeanNameUrlHandlerMapping();
beanNameUrlHandlerMapping.setOrder(1);
return beanNameUrlHandlerMapping;
}
use of org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping in project spring-framework by spring-projects.
the class MvcNamespaceTests method testResources.
@Test
@SuppressWarnings("deprecation")
public void testResources() throws Exception {
loadBeanDefinitions("mvc-config-resources.xml");
HttpRequestHandlerAdapter adapter = appContext.getBean(HttpRequestHandlerAdapter.class);
assertThat(adapter).isNotNull();
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
ContentNegotiationManager manager = mapping.getContentNegotiationManager();
ResourceHttpRequestHandler handler = appContext.getBean(ResourceHttpRequestHandler.class);
assertThat(handler).isNotNull();
assertThat(handler.getContentNegotiationManager()).isSameAs(manager);
SimpleUrlHandlerMapping resourceMapping = appContext.getBean(SimpleUrlHandlerMapping.class);
assertThat(resourceMapping).isNotNull();
assertThat(resourceMapping.getOrder()).isEqualTo(Ordered.LOWEST_PRECEDENCE - 1);
BeanNameUrlHandlerMapping beanNameMapping = appContext.getBean(BeanNameUrlHandlerMapping.class);
assertThat(beanNameMapping).isNotNull();
assertThat(beanNameMapping.getOrder()).isEqualTo(2);
ResourceUrlProvider urlProvider = appContext.getBean(ResourceUrlProvider.class);
assertThat(urlProvider).isNotNull();
Map<String, MappedInterceptor> beans = appContext.getBeansOfType(MappedInterceptor.class);
List<Class<?>> interceptors = beans.values().stream().map(mappedInterceptor -> mappedInterceptor.getInterceptor().getClass()).collect(Collectors.toList());
assertThat(interceptors).contains(ConversionServiceExposingInterceptor.class, ResourceUrlProviderExposingInterceptor.class);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRequestURI("/resources/foo.css");
request.setMethod("GET");
HandlerExecutionChain chain = resourceMapping.getHandler(request);
assertThat(chain).isNotNull();
assertThat(chain.getHandler() instanceof ResourceHttpRequestHandler).isTrue();
MockHttpServletResponse response = new MockHttpServletResponse();
for (HandlerInterceptor interceptor : chain.getInterceptorList()) {
interceptor.preHandle(request, response, chain.getHandler());
}
ModelAndView mv = adapter.handle(request, response, chain.getHandler());
assertThat((Object) mv).isNull();
}
use of org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping in project spring-framework by spring-projects.
the class MvcNamespaceTests method testViewControllersDefaultConfig.
@Test
public void testViewControllersDefaultConfig() {
loadBeanDefinitions("mvc-config-view-controllers-minimal.xml");
SimpleUrlHandlerMapping hm = this.appContext.getBean(SimpleUrlHandlerMapping.class);
assertThat(hm).isNotNull();
ParameterizableViewController viewController = (ParameterizableViewController) hm.getUrlMap().get("/path");
assertThat(viewController).isNotNull();
assertThat(viewController.getViewName()).isEqualTo("home");
ParameterizableViewController redirectViewController = (ParameterizableViewController) hm.getUrlMap().get("/old");
assertThat(redirectViewController).isNotNull();
assertThat(redirectViewController.getView()).isInstanceOf(RedirectView.class);
ParameterizableViewController statusViewController = (ParameterizableViewController) hm.getUrlMap().get("/bad");
assertThat(statusViewController).isNotNull();
assertThat(statusViewController.getStatusCode().value()).isEqualTo(404);
BeanNameUrlHandlerMapping beanNameMapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class);
assertThat(beanNameMapping).isNotNull();
assertThat(beanNameMapping.getOrder()).isEqualTo(2);
}
use of org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping in project spring-framework by spring-projects.
the class TestPathHelper method beanNameUrlHandlerMapping.
@Test
public void beanNameUrlHandlerMapping() {
loadBeanDefinitions("mvc-config.xml");
BeanNameUrlHandlerMapping mapping = this.appContext.getBean(BeanNameUrlHandlerMapping.class);
assertThat(mapping).isNotNull();
assertThat(mapping.getOrder()).isEqualTo(2);
}
Aggregations