Springframework自定义嵌套标记问题

时间:2015-03-28 01:32:51

标签: spring spring-bean

我正在尝试创建基于XSD的自定义配置。我有自定义标签,它依次有另一个自定义标签。解析内部标记时,我找不到命名空间处理程序。它无法找到http://www.springframework.org/schema/beans架构的处理程序类。

示例XML:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:or="http://www.searsoutlet.com/schema/rest"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
    http://www.mycompany.com/schema/rest http://www.mycompany.com/schema/rest-util-v1.0.xsd">

    <or:springRestTemplate id="customTemplateTest" >
        <or:basicAuth id="templateCreds" userName="restUser" password="restPassword" />
        <or:httpHeaders >
            <map>
                <entry key="headerName" value="headerValue" />
            </map>
        </or:httpHeaders>
    </or:springRestTemplate>

</beans>

解析器代码:

@Override
    protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
        BeanDefinitionBuilder restTemplate = BeanDefinitionBuilder.rootBeanDefinition(SpringRestTemplateWithInterceptorsFactoryBean.class);

        List<Element> credentials = DomUtils.getChildElementsByTagName(element, AUTH_CHILD_ELEMENT);
        if (credentials != null && !credentials.isEmpty()) {
            restTemplate.addPropertyValue("basicAuth", parserContext.getDelegate().parseCustomElement(credentials.get(0)));
        }

        List<Element> httpHeadersElements = DomUtils.getChildElementsByTagName(element, HTTP_HEADER_CHILD_ELEMENT);
        if (httpHeadersElements != null && !httpHeadersElements.isEmpty()) {
            httpHeadersElements = DomUtils.getChildElementsByTagName(httpHeadersElements.get(0), "map");
        }

        if (httpHeadersElements != null && !httpHeadersElements.isEmpty()) {
            restTemplate.addPropertyValue("httpHeaders", parserContext.getDelegate().parseCustomElement(httpHeadersElements.get(0)));
        }

        return restTemplate.getBeanDefinition();
    }

我在这一行上收到错误:

restTemplate.addPropertyValue("httpHeaders", parserContext.getDelegate().parseCustomElement(httpHeadersElements.get(0)));

我试图调试这个问题。我看到parserContext已经加载了所有Spring模式处理程序,期望bean模式。

0 个答案:

没有答案