本文整理汇总了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;
}
示例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());
}
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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());
}
}
示例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"));
}
示例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"));
}