Spring的meta标签

时间:2023-07-27 20:43:20

Spring的解析源码

    public void parseMetaElements(Element ele, BeanMetadataAttributeAccessor attributeAccessor) {
//获取当前节点的所有子元素
     NodeList nl = ele.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
//提取meta
       if (isCandidateElement(node) && nodeNameEquals(node, META_ELEMENT)) {
Element metaElement = (Element) node;
String key = metaElement.getAttribute(KEY_ATTRIBUTE);
String value = metaElement.getAttribute(VALUE_ATTRIBUTE);
//使用key、value构造BeanMetadataAttribute
          BeanMetadataAttribute attribute = new BeanMetadataAttribute(key, value);
attribute.setSource(extractSource(metaElement));
//记录信息
          attributeAccessor.addMetadataAttribute(attribute);
}
}
}

meta属性的使用

<meta key="special-data" value="sprecial stragey" />

BeanDefinition bd;

String beanCategoriesExpression = (String)bd.getAttribute(CATEGORY_META_KEY);