使用SimpleUrlHandlerMapping解析器

时间:2015-02-18 21:03:34

标签: java spring spring-mvc spring-boot

尝试使用带有SimpleUrlHandlerMapping的解析器并运行问题。它构建并运行但每次调用url时,我都有一个NULL / NULL用于控制器/动作

我误解了如何一起使用这些吗?

    public PropertiesMethodNameResolver methodMapping(String entryPoint, String controllerName, List actions){
    PropertiesMethodNameResolver resolver = new PropertiesMethodNameResolver();

    Properties mappings = new Properties();
    actions.each(){ it ->
        mappings.put("/"+entryPoint+"/"+controllerName+"/"+it+"/**", "${it}".toString());
    }
    resolver.setMappings(mappings);
    return resolver
}

@Bean
public SimpleUrlHandlerMapping urlMapping(ApplicationContext context) {
    String apiName = this.apiName.toString()
    String apiVersion = this.version.toString()
    String entryPoint = (apiName)?"${apiName}_v${apiVersion}".toString():"v${apiVersion}".toString()

    //apiCacheService.deleteAll();
    LinkedHashMap urlList = populateCache()

    SimpleUrlHandlerMapping ret = new SimpleUrlHandlerMapping();

    //HandlerInterceptor hi = new HandlerInterceptor()[ apiInterceptor() ]
    ApiInterceptor apiInterceptor = apiInterceptor()
    ret.setInterceptors(apiInterceptor);

    ret.setOrder(Integer.MAX_VALUE-2);

    String[] controllers = context.getBeanNamesForType(MultiActionController.class)

    Properties mappings = new Properties();
    urlList.each{ controller, actions ->
        String controllerName = "${controller}Controller".toString()
        if(controllers.contains(controllerName)){
            PropertiesMethodNameResolver resolver = methodMapping(entryPoint,controllerName,actions)
            MultiActionController cont = context.getBean(controllerName)
            cont.setMethodNameResolver(resolver);

            actions.each{ action ->
                mappings.put("/"+entryPoint+"/"+controller+"/"+action+"/**", cont);
            }
            ret.setUrlMap(mappings);
        }
    }
    //ret.setMappings(mappings);

    return ret;
}

0 个答案:

没有答案