本文整理汇总了Java中org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping类的典型用法代码示例。如果您正苦于以下问题:Java RequestMappingHandlerMapping类的具体用法?Java RequestMappingHandlerMapping怎么用?Java RequestMappingHandlerMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RequestMappingHandlerMapping类属于org.springframework.web.servlet.mvc.method.annotation包,在下文中一共展示了RequestMappingHandlerMapping类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCustomConversionService
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的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: onApplicationEvent
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Override
public void onApplicationEvent ( ContextRefreshedEvent event ) {
final RequestMappingHandlerMapping requestMappingHandlerMapping =
applicationContext.getBean( RequestMappingHandlerMapping.class );
final Map< RequestMappingInfo, HandlerMethod > handlerMethods =
requestMappingHandlerMapping.getHandlerMethods();
this.handlerMethods = handlerMethods;
handlerMethods.keySet().forEach( mappingInfo -> {
Map< Set< String >, Set< RequestMethod > > mapping = Collections.singletonMap(
mappingInfo.getPatternsCondition().getPatterns() ,
this.getMethods( mappingInfo.getMethodsCondition().getMethods() )
);
requestMappingInfos.add( mapping );
} );
requestMappingUris.addAll(
handlerMethods.keySet()
.parallelStream()
.map( mappingInfo -> mappingInfo.getPatternsCondition().getPatterns() )
.collect( Collectors.toList() )
);
}
示例3: of
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
public static List<OriginalRequestMappingInfo> of(RequestMappingHandlerMapping handlerMapping) {
List<OriginalRequestMappingInfo> result = new ArrayList<OriginalRequestMappingInfo>();
for (Entry<RequestMappingInfo, HandlerMethod> entry : handlerMapping.getHandlerMethods().entrySet()) {
RequestMappingInfo requestMappingInfo = entry.getKey();
OriginalRequestMappingInfo o = new OriginalRequestMappingInfo();
o.setSite(Site.of(requestMappingInfo.getPatternsCondition().getPatterns().iterator().next()));
o.setMethods(requestMappingInfo.getMethodsCondition().getMethods());
o.setPatterns(requestMappingInfo.getPatternsCondition().getPatterns());
Set<String> params = new HashSet<>();
for (NameValueExpression<String> nameValueExpression : requestMappingInfo.getParamsCondition().getExpressions()) {
params.add(nameValueExpression.toString());
}
o.setParams(params);
result.add(o);
}
return result.stream().sorted().collect(Collectors.toList());
}
示例4: doTestCustomValidator
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的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);
}
示例5: testBeanDecoration
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void testBeanDecoration() throws Exception {
loadBeanDefinitions("mvc-config-bean-decoration.xml", 16);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(mapping);
mapping.setDefaultHandler(handlerMethod);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
HandlerExecutionChain chain = mapping.getHandler(request);
assertEquals(3, chain.getInterceptors().length);
assertTrue(chain.getInterceptors()[0] instanceof ConversionServiceExposingInterceptor);
assertTrue(chain.getInterceptors()[1] instanceof LocaleChangeInterceptor);
assertTrue(chain.getInterceptors()[2] instanceof ThemeChangeInterceptor);
LocaleChangeInterceptor interceptor = (LocaleChangeInterceptor) chain.getInterceptors()[1];
assertEquals("lang", interceptor.getParamName());
ThemeChangeInterceptor interceptor2 = (ThemeChangeInterceptor) chain.getInterceptors()[2];
assertEquals("style", interceptor2.getParamName());
}
示例6: testContentNegotiationManager
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void testContentNegotiationManager() throws Exception {
loadBeanDefinitions("mvc-config-content-negotiation-manager.xml", 15);
RequestMappingHandlerMapping mapping = appContext.getBean(RequestMappingHandlerMapping.class);
ContentNegotiationManager manager = mapping.getContentNegotiationManager();
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.xml");
NativeWebRequest webRequest = new ServletWebRequest(request);
assertEquals(Arrays.asList(MediaType.valueOf("application/rss+xml")), manager.resolveMediaTypes(webRequest));
ViewResolverComposite compositeResolver = this.appContext.getBean(ViewResolverComposite.class);
assertNotNull(compositeResolver);
assertEquals("Actual: " + compositeResolver.getViewResolvers(), 1, compositeResolver.getViewResolvers().size());
ViewResolver resolver = compositeResolver.getViewResolvers().get(0);
assertEquals(ContentNegotiatingViewResolver.class, resolver.getClass());
ContentNegotiatingViewResolver cnvr = (ContentNegotiatingViewResolver) resolver;
assertSame(manager, cnvr.getContentNegotiationManager());
}
示例7: testPathMatchingHandlerMappings
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void testPathMatchingHandlerMappings() throws Exception {
loadBeanDefinitions("mvc-config-path-matching-mappings.xml", 23);
RequestMappingHandlerMapping requestMapping = appContext.getBean(RequestMappingHandlerMapping.class);
assertNotNull(requestMapping);
assertEquals(TestPathHelper.class, requestMapping.getUrlPathHelper().getClass());
assertEquals(TestPathMatcher.class, requestMapping.getPathMatcher().getClass());
SimpleUrlHandlerMapping viewController = appContext.getBean(VIEWCONTROLLER_BEAN_NAME, SimpleUrlHandlerMapping.class);
assertNotNull(viewController);
assertEquals(TestPathHelper.class, viewController.getUrlPathHelper().getClass());
assertEquals(TestPathMatcher.class, viewController.getPathMatcher().getClass());
for (SimpleUrlHandlerMapping handlerMapping : appContext.getBeansOfType(SimpleUrlHandlerMapping.class).values()) {
assertNotNull(handlerMapping);
assertEquals(TestPathHelper.class, handlerMapping.getUrlPathHelper().getClass());
assertEquals(TestPathMatcher.class, handlerMapping.getPathMatcher().getClass());
}
}
示例8: requestMappingHandlerMapping
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void requestMappingHandlerMapping() throws Exception {
ApplicationContext context = initContext(WebConfig.class, ScopedController.class, ScopedProxyController.class);
RequestMappingHandlerMapping handlerMapping = context.getBean(RequestMappingHandlerMapping.class);
assertEquals(0, handlerMapping.getOrder());
HandlerExecutionChain chain = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/"));
assertNotNull(chain);
assertNotNull(chain.getInterceptors());
assertEquals(ConversionServiceExposingInterceptor.class, chain.getInterceptors()[0].getClass());
chain = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/scoped"));
assertNotNull("HandlerExecutionChain for '/scoped' mapping should not be null.", chain);
chain = handlerMapping.getHandler(new MockHttpServletRequest("GET", "/scopedProxy"));
assertNotNull("HandlerExecutionChain for '/scopedProxy' mapping should not be null.", chain);
}
示例9: suffixPatternMatch
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void suffixPatternMatch() throws Exception {
TestStandaloneMockMvcBuilder builder = new TestStandaloneMockMvcBuilder(new PersonController());
builder.setUseSuffixPatternMatch(false);
builder.build();
RequestMappingHandlerMapping hm = builder.wac.getBean(RequestMappingHandlerMapping.class);
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/persons");
HandlerExecutionChain chain = hm.getHandler(request);
assertNotNull(chain);
assertEquals("persons", ((HandlerMethod) chain.getHandler()).getMethod().getName());
request = new MockHttpServletRequest("GET", "/persons.xml");
chain = hm.getHandler(request);
assertNull(chain);
}
示例10: sitePreferenceHandlerInterceptorRegistered
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void sitePreferenceHandlerInterceptorRegistered() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
SitePreferenceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
RequestMappingHandlerMapping mapping = this.context
.getBean(RequestMappingHandlerMapping.class);
HandlerInterceptor[] interceptors = mapping
.getHandler(new MockHttpServletRequest()).getInterceptors();
assertThat(interceptors)
.hasAtLeastOneElementOfType(SitePreferenceHandlerInterceptor.class);
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:SitePreferenceAutoConfigurationTests.java
示例11: webMvcRegistrations
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的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: getHandlerExecution
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
protected HandlerExecutionChain getHandlerExecution(HttpServletRequest request) throws Exception {
WebApplicationContext appContext = WebApplicationContextUtils
.getRequiredWebApplicationContext(request.getServletContext());
HandlerMapping bean = appContext.getBean(RequestMappingHandlerMapping.class);
HandlerExecutionChain handler = bean.getHandler(request);
if (handler == null) {
ServletContext servletContext = request.getServletContext();
Enumeration<?> attrNameEnum = servletContext.getAttributeNames();
while (attrNameEnum.hasMoreElements()) {
String attrName = (String) attrNameEnum.nextElement();
if (attrName.startsWith(FrameworkServlet.SERVLET_CONTEXT_PREFIX)) {
appContext = (WebApplicationContext) servletContext.getAttribute(attrName);
bean = appContext.getBean(RequestMappingHandlerMapping.class);
handler = bean.getHandler(request);
if (handler != null) {
break;
}
}
}
}
return handler;
}
示例13: sitePreferenceHandlerInterceptorRegistered
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void sitePreferenceHandlerInterceptorRegistered() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
SitePreferenceAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
RequestMappingHandlerMapping mapping = this.context
.getBean(RequestMappingHandlerMapping.class);
HandlerInterceptor[] interceptors = mapping
.getHandler(new MockHttpServletRequest()).getInterceptors();
assertThat(interceptors,
hasItemInArray(instanceOf(SitePreferenceHandlerInterceptor.class)));
}
示例14: deviceResolverHandlerInterceptorRegistered
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
@Test
public void deviceResolverHandlerInterceptorRegistered() throws Exception {
this.context = new AnnotationConfigWebApplicationContext();
this.context.setServletContext(new MockServletContext());
this.context.register(Config.class, WebMvcAutoConfiguration.class,
HttpMessageConvertersAutoConfiguration.class,
DeviceResolverAutoConfiguration.class,
PropertyPlaceholderAutoConfiguration.class);
this.context.refresh();
RequestMappingHandlerMapping mapping = this.context
.getBean(RequestMappingHandlerMapping.class);
HandlerInterceptor[] interceptors = mapping
.getHandler(new MockHttpServletRequest()).getInterceptors();
assertThat(interceptors,
hasItemInArray(instanceOf(DeviceResolverHandlerInterceptor.class)));
}
示例15: getRequestMappingHandlerMappingInfoMapForLog
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping; //导入依赖的package包/类
/**
* 获得 request mapping handler mapping info map for LOGGER.
*
* @param webApplicationContext
* the web application context
* @return the request mapping handler mapping info map for log
*/
public static final Map<String, Object> getRequestMappingHandlerMappingInfoMapForLog(WebApplicationContext webApplicationContext){
RequestMappingHandlerMapping requestMappingHandlerMapping = webApplicationContext.getBean(RequestMappingHandlerMapping.class);
Map<String, Object> mappingInfoMap = newLinkedHashMap();
mappingInfoMap.put("useRegisteredSuffixPatternMatch()", requestMappingHandlerMapping.useRegisteredSuffixPatternMatch());
mappingInfoMap.put("useSuffixPatternMatch()", requestMappingHandlerMapping.useSuffixPatternMatch());
mappingInfoMap.put("useTrailingSlashMatch()", requestMappingHandlerMapping.useTrailingSlashMatch());
mappingInfoMap.put("getDefaultHandler()", requestMappingHandlerMapping.getDefaultHandler());
mappingInfoMap.put("getFileExtensions()", requestMappingHandlerMapping.getFileExtensions());
mappingInfoMap.put("getOrder()", requestMappingHandlerMapping.getOrder());
mappingInfoMap.put("getPathMatcher()", requestMappingHandlerMapping.getPathMatcher());
mappingInfoMap.put("getUrlPathHelper()", requestMappingHandlerMapping.getUrlPathHelper());
//---------------------------------------------------------------
Map<String, RequestMappingInfo> methodAndRequestMappingInfoMapMap = buildMethodAndRequestMappingInfoMap(
requestMappingHandlerMapping);
mappingInfoMap.put("methodAndRequestMappingInfoMapMap", methodAndRequestMappingInfoMapMap);
return mappingInfoMap;
}