Example usage for org.springframework.web.servlet.handler BeanNameUrlHandlerMapping setApplicationContext

List of usage examples for org.springframework.web.servlet.handler BeanNameUrlHandlerMapping setApplicationContext

Introduction

In this page you can find the example usage for org.springframework.web.servlet.handler BeanNameUrlHandlerMapping setApplicationContext.

Prototype

@Override
    public final void setApplicationContext(@Nullable ApplicationContext context) throws BeansException 

Source Link

Usage

From source file:org.trpr.platform.servicefw.impl.spring.web.HomeController.java

/**
 * //from   ww  w  .  j a v  a2 s  .c om
 */
private void findResources() {
    Map<String, Object> handlerMap = new HashMap<String, Object>();

    DefaultAnnotationHandlerMapping annotationMapping = new DefaultAnnotationHandlerMapping();
    annotationMapping.setApplicationContext(applicationContext);
    annotationMapping.initApplicationContext();
    handlerMap.putAll(annotationMapping.getHandlerMap());

    BeanNameUrlHandlerMapping beanMapping = new BeanNameUrlHandlerMapping();
    beanMapping.setApplicationContext(applicationContext);
    beanMapping.initApplicationContext();
    handlerMap.putAll(beanMapping.getHandlerMap());

    this.urls = findUniqueUrls(handlerMap.keySet());
    this.defaultResources = findMethods(handlerMap, this.urls);
    this.jsonResources = new ArrayList<ResourceInfo>();
    for (Iterator<ResourceInfo> iterator = this.defaultResources.iterator(); iterator.hasNext();) {
        ResourceInfo info = (ResourceInfo) iterator.next();
        if (info.getUrl().endsWith(".json")) {
            iterator.remove();
            this.jsonResources.add(info);
        }
    }

}

From source file:org.springframework.batch.admin.web.util.HomeController.java

private void findResources() {
    Map<String, Object> handlerMap = new HashMap<String, Object>();

    DefaultAnnotationHandlerMapping annotationMapping = new DefaultAnnotationHandlerMapping();
    annotationMapping.setApplicationContext(applicationContext);
    annotationMapping.initApplicationContext();
    handlerMap.putAll(annotationMapping.getHandlerMap());

    BeanNameUrlHandlerMapping beanMapping = new BeanNameUrlHandlerMapping();
    beanMapping.setApplicationContext(applicationContext);
    beanMapping.initApplicationContext();
    handlerMap.putAll(beanMapping.getHandlerMap());

    this.urls = findUniqueUrls(handlerMap.keySet());
    this.defaultResources = findMethods(handlerMap, this.urls);
    this.jsonResources = new ArrayList<ResourceInfo>();
    for (Iterator<ResourceInfo> iterator = this.defaultResources.iterator(); iterator.hasNext();) {
        ResourceInfo info = (ResourceInfo) iterator.next();
        if (info.getUrl().endsWith(".json")) {
            iterator.remove();//w  ww .j a va 2 s. co  m
            this.jsonResources.add(info);
        }
    }

}