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


Java AbstractHandlerMapping类代码示例

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


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

示例1: resourceHandlerMapping

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
/**
 * Return a handler mapping ordered at Integer.MAX_VALUE-1 with mapped
 * resource handlers. To configure resource handling, override
 * {@link #addResourceHandlers}.
 */
@Bean
public HandlerMapping resourceHandlerMapping() {
	ResourceHandlerRegistry registry = new ResourceHandlerRegistry(this.applicationContext, this.servletContext);
	addResourceHandlers(registry);

	AbstractHandlerMapping handlerMapping = registry.getHandlerMapping();
	if (handlerMapping != null) {
		handlerMapping.setPathMatcher(mvcPathMatcher());
		handlerMapping.setUrlPathHelper(mvcUrlPathHelper());
		handlerMapping.setInterceptors(new HandlerInterceptor[] {
				new ResourceUrlProviderExposingInterceptor(mvcResourceUrlProvider())});
		handlerMapping.setCorsConfigurations(getCorsConfigurations());
	}
	else {
		handlerMapping = new EmptyHandlerMapping();
	}
	return handlerMapping;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:WebMvcConfigurationSupport.java

示例2: testCorsMinimal

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
@Test
public void testCorsMinimal() throws Exception {
	loadBeanDefinitions("mvc-config-cors-minimal.xml", 14);

	String[] beanNames = appContext.getBeanNamesForType(AbstractHandlerMapping.class);
	assertEquals(2, beanNames.length);
	for (String beanName : beanNames) {
		AbstractHandlerMapping handlerMapping = (AbstractHandlerMapping)appContext.getBean(beanName);
		assertNotNull(handlerMapping);
		Map<String, CorsConfiguration> configs = handlerMapping.getCorsConfigurations();
		assertNotNull(configs);
		assertEquals(1, configs.size());
		CorsConfiguration config = configs.get("/**");
		assertNotNull(config);
		assertArrayEquals(new String[]{"*"}, config.getAllowedOrigins().toArray());
		assertArrayEquals(new String[]{"GET", "HEAD", "POST"}, config.getAllowedMethods().toArray());
		assertArrayEquals(new String[]{"*"}, config.getAllowedHeaders().toArray());
		assertNull(config.getExposedHeaders());
		assertTrue(config.getAllowCredentials());
		assertEquals(new Long(1600), config.getMaxAge());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:MvcNamespaceTests.java

示例3: getHandlerMapping

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
/**
 * Return a {@link HandlerMapping} with mapped {@link HttpRequestHandler}s.
 */
public AbstractHandlerMapping getHandlerMapping() {
	Map<String, Object> urlMap = new LinkedHashMap<String, Object>();
	for (ServletWebSocketHandlerRegistration registration : this.registrations) {
		MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
		for (HttpRequestHandler httpHandler : mappings.keySet()) {
			for (String pattern : mappings.get(httpHandler)) {
				urlMap.put(pattern, httpHandler);
			}
		}
	}
	WebSocketHandlerMapping hm = new WebSocketHandlerMapping();
	hm.setUrlMap(urlMap);
	hm.setOrder(this.order);
	if (this.urlPathHelper != null) {
		hm.setUrlPathHelper(this.urlPathHelper);
	}
	return hm;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:22,代码来源:ServletWebSocketHandlerRegistry.java

示例4: getHandlerMapping

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
/**
 * Return a handler mapping with the mapped ViewControllers; or {@code null}
 * in case of no registrations.
 */
public AbstractHandlerMapping getHandlerMapping() {
	Map<String, Object> urlMap = new LinkedHashMap<String, Object>();
	for (WebMvcStompWebSocketEndpointRegistration registration : this.registrations) {
		MultiValueMap<HttpRequestHandler, String> mappings = registration.getMappings();
		for (HttpRequestHandler httpHandler : mappings.keySet()) {
			for (String pattern : mappings.get(httpHandler)) {
				urlMap.put(pattern, httpHandler);
			}
		}
	}
	WebSocketHandlerMapping hm = new WebSocketHandlerMapping();
	hm.setUrlMap(urlMap);
	hm.setOrder(this.order);
	if (this.urlPathHelper != null) {
		hm.setUrlPathHelper(this.urlPathHelper);
	}
	return hm;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:WebMvcStompEndpointRegistry.java

示例5: initApplicationContext

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
@Override
protected void initApplicationContext() throws BeansException {
	// new Exception("initApplicationContext").printStackTrace();
	// 修改拦截器排序
	try {
		Field field = AbstractHandlerMapping.class.getDeclaredField("interceptors");
		field.setAccessible(true);
		@SuppressWarnings("unchecked")
		List<Object> interceptors = (List<Object>) field.get(this);
		AnnotationAwareOrderComparator.sort(interceptors);
		// System.out.println("interceptors:" + interceptors);
	}
	catch (Exception e) {
		throw new RuntimeException(e.getMessage(), e);
	}
	super.initApplicationContext();
}
 
开发者ID:tanhaichao,项目名称:leopard,代码行数:18,代码来源:LeopardHandlerMapping.java

示例6: getHandlerMapping

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
/**
 * Return a handler mapping with the mapped ViewControllers; or {@code null} in case
 * of no registrations.
 */
public AbstractHandlerMapping getHandlerMapping() {
	Map<String, Object> urlMap = new LinkedHashMap<>();
	for (WebMvcWampWebSocketEndpointRegistration registration : this.registrations) {
		MultiValueMap<HttpRequestHandler, String> mappings = registration
				.getMappings();
		for (HttpRequestHandler httpHandler : mappings.keySet()) {
			for (String pattern : mappings.get(httpHandler)) {
				urlMap.put(pattern, httpHandler);
			}
		}
	}
	SimpleUrlHandlerMapping hm = new SimpleUrlHandlerMapping();
	hm.setUrlMap(urlMap);
	hm.setOrder(this.order);
	if (this.urlPathHelper != null) {
		hm.setUrlPathHelper(this.urlPathHelper);
	}
	return hm;
}
 
开发者ID:ralscha,项目名称:wampspring,代码行数:24,代码来源:WebMvcWampEndpointRegistry.java

示例7: getHandlerMapping

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
/**
 * Returns a handler mapping with the mapped ViewControllers; or {@code null} in case of no registrations.
 */
protected AbstractHandlerMapping getHandlerMapping() {
	if (registrations.isEmpty()) {
		return null;
	}

	Map<String, Object> urlMap = new LinkedHashMap<String, Object>();
	for (ViewControllerRegistration registration : registrations) {
		urlMap.put(registration.getUrlPath(), registration.getViewController());
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(order);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:19,代码来源:ViewControllerRegistry.java

示例8: getHandlerMapping

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
/**
 * Return a handler mapping with the mapped resource handlers; or {@code null} in case of no registrations.
 */
protected AbstractHandlerMapping getHandlerMapping() {
	if (registrations.isEmpty()) {
		return null;
	}

	Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<String, HttpRequestHandler>();
	for (ResourceHandlerRegistration registration : registrations) {
		for (String pathPattern : registration.getPathPatterns()) {
			ResourceHttpRequestHandler requestHandler = registration.getRequestHandler();
			requestHandler.setServletContext(servletContext);
			requestHandler.setApplicationContext(applicationContext);
			urlMap.put(pathPattern, requestHandler);
		}
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(order);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:24,代码来源:ResourceHandlerRegistry.java

示例9: getHandlerMapping

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
/**
 * Return a handler mapping instance ordered at {@link Integer#MAX_VALUE} containing the
 * {@link DefaultServletHttpRequestHandler} instance mapped to {@code "/**"}; or {@code null} if
 * default servlet handling was not been enabled.
 */
protected AbstractHandlerMapping getHandlerMapping() {
	if (handler == null) {
		return null;
	}

	Map<String, HttpRequestHandler> urlMap = new HashMap<String, HttpRequestHandler>();
	urlMap.put("/**", handler);

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(Integer.MAX_VALUE);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:DefaultServletHandlerConfigurer.java

示例10: getHandlerMapping

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
/**
 * Return a handler mapping with the mapped resource handlers; or {@code null} in case of no registrations.
 */
protected AbstractHandlerMapping getHandlerMapping() {
	if (registrations.isEmpty()) {
		return null;
	}

	Map<String, HttpRequestHandler> urlMap = new LinkedHashMap<String, HttpRequestHandler>();
	for (ResourceHandlerRegistration registration : this.registrations) {
		for (String pathPattern : registration.getPathPatterns()) {
			ResourceHttpRequestHandler handler = registration.getRequestHandler();
			handler.setServletContext(this.servletContext);
			handler.setApplicationContext(this.appContext);
			try {
				handler.afterPropertiesSet();
			}
			catch (Exception e) {
				throw new BeanInitializationException("Failed to init ResourceHttpRequestHandler", e);
			}
			urlMap.put(pathPattern, handler);
		}
	}

	SimpleUrlHandlerMapping handlerMapping = new SimpleUrlHandlerMapping();
	handlerMapping.setOrder(order);
	handlerMapping.setUrlMap(urlMap);
	return handlerMapping;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:ResourceHandlerRegistry.java

示例11: viewControllerHandlerMapping

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
/**
 * Return a handler mapping ordered at 1 to map URL paths directly to
 * view names. To configure view controllers, override
 * {@link #addViewControllers}.
 */
@Bean
public HandlerMapping viewControllerHandlerMapping() {
	ViewControllerRegistry registry = new ViewControllerRegistry();
	registry.setApplicationContext(this.applicationContext);
	addViewControllers(registry);

	AbstractHandlerMapping handlerMapping = registry.getHandlerMapping();
	handlerMapping = (handlerMapping != null ? handlerMapping : new EmptyHandlerMapping());
	handlerMapping.setPathMatcher(mvcPathMatcher());
	handlerMapping.setUrlPathHelper(mvcUrlPathHelper());
	handlerMapping.setInterceptors(getInterceptors());
	handlerMapping.setCorsConfigurations(getCorsConfigurations());
	return handlerMapping;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:WebMvcConfigurationSupport.java

示例12: defaultServletHandlerMapping

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
/**
 * Return a handler mapping ordered at Integer.MAX_VALUE with a mapped
 * default servlet handler. To configure "default" Servlet handling,
 * override {@link #configureDefaultServletHandling}.
 */
@Bean
public HandlerMapping defaultServletHandlerMapping() {
	DefaultServletHandlerConfigurer configurer = new DefaultServletHandlerConfigurer(servletContext);
	configureDefaultServletHandling(configurer);
	AbstractHandlerMapping handlerMapping = configurer.getHandlerMapping();
	handlerMapping = handlerMapping != null ? handlerMapping : new EmptyHandlerMapping();
	return handlerMapping;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:WebMvcConfigurationSupport.java

示例13: testCors

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
@Test
public void testCors() throws Exception {
	loadBeanDefinitions("mvc-config-cors.xml", 14);

	String[] beanNames = appContext.getBeanNamesForType(AbstractHandlerMapping.class);
	assertEquals(2, beanNames.length);
	for (String beanName : beanNames) {
		AbstractHandlerMapping handlerMapping = (AbstractHandlerMapping)appContext.getBean(beanName);
		assertNotNull(handlerMapping);
		Map<String, CorsConfiguration> configs = handlerMapping.getCorsConfigurations();
		assertNotNull(configs);
		assertEquals(2, configs.size());
		CorsConfiguration config = configs.get("/api/**");
		assertNotNull(config);
		assertArrayEquals(new String[]{"http://domain1.com", "http://domain2.com"}, config.getAllowedOrigins().toArray());
		assertArrayEquals(new String[]{"GET", "PUT"}, config.getAllowedMethods().toArray());
		assertArrayEquals(new String[]{"header1", "header2", "header3"}, config.getAllowedHeaders().toArray());
		assertArrayEquals(new String[]{"header1", "header2"}, config.getExposedHeaders().toArray());
		assertFalse(config.getAllowCredentials());
		assertEquals(new Long(123), config.getMaxAge());
		config = configs.get("/resources/**");
		assertArrayEquals(new String[]{"http://domain1.com"}, config.getAllowedOrigins().toArray());
		assertArrayEquals(new String[]{"GET", "HEAD", "POST"}, config.getAllowedMethods().toArray());
		assertArrayEquals(new String[]{"*"}, config.getAllowedHeaders().toArray());
		assertNull(config.getExposedHeaders());
		assertTrue(config.getAllowCredentials());
		assertEquals(new Long(1600), config.getMaxAge());
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:30,代码来源:MvcNamespaceTests.java

示例14: emptyViewControllerHandlerMapping

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
@Test
public void emptyViewControllerHandlerMapping() {
	ApplicationContext context = initContext(WebConfig.class);
	String name = "viewControllerHandlerMapping";
	AbstractHandlerMapping handlerMapping = context.getBean(name, AbstractHandlerMapping.class);

	assertNotNull(handlerMapping);
	assertEquals(Integer.MAX_VALUE, handlerMapping.getOrder());
	assertTrue(handlerMapping.getClass().getName().endsWith("EmptyHandlerMapping"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:11,代码来源:WebMvcConfigurationSupportTests.java

示例15: emptyResourceHandlerMapping

import org.springframework.web.servlet.handler.AbstractHandlerMapping; //导入依赖的package包/类
@Test
public void emptyResourceHandlerMapping() {
	ApplicationContext context = initContext(WebConfig.class);
	AbstractHandlerMapping handlerMapping = context.getBean("resourceHandlerMapping", AbstractHandlerMapping.class);

	assertNotNull(handlerMapping);
	assertEquals(Integer.MAX_VALUE, handlerMapping.getOrder());
	assertTrue(handlerMapping.getClass().getName().endsWith("EmptyHandlerMapping"));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:10,代码来源:WebMvcConfigurationSupportTests.java


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