nacos-spring-project 的 xml 配置
Posted 偶尔发呆
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nacos-spring-project 的 xml 配置相关的知识,希望对你有一定的参考价值。
nacos-spring-context 作为一座桥连接 spring 项目和 nacos-client
在 spring 项目中使用自定义的 xml 标签
1. 编写 xsd 文件
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://nacos.io/schema/nacos" targetNamespace="http://nacos.io/schema/nacos"> <xsd:import namespace="http://www.w3.org/XML/1998/namespace"/> <xsd:annotation> <xsd:documentation> <![CDATA[ Nacos Framework Schema ]]> </xsd:documentation> </xsd:annotation> <xsd:element name="annotation-driven"> <xsd:annotation> <xsd:documentation> <![CDATA[ Activates various Nacos Spring‘s annotations : @NacosInjected @NacosConfigListener @NacosPropertySource @NacosPropertySources @NacosConfigProperties / @NacosProperty / @NacosIgnore ]]></xsd:documentation> </xsd:annotation> </xsd:element> <xsd:element name="global-properties"> <xsd:annotation> <xsd:documentation> <![CDATA[ Register Nacos global Properties whose values are configured from attributes. ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:attribute name="endpoint" default="${nacos.endpoint:}"/> <xsd:attribute name="namespace" default="${nacos.endpoint:}"/> <xsd:attribute name="access-key" default="${nacos.access-key:}"/> <xsd:attribute name="secret-key" default="${nacos.secret-key:}"/> <xsd:attribute name="server-addr" default="${nacos.server-addr:}"/> <xsd:attribute name="context-path" default="${nacos.context-path:}"/> <xsd:attribute name="cluster-name" default="${nacos.cluster-name:}"/> <xsd:attribute name="encode" default="${nacos.encode:UTF-8}"/> </xsd:complexType> </xsd:element> <xsd:element name="property-source"> <xsd:annotation> <xsd:documentation> <![CDATA[ Add Nacos property source ]]> </xsd:documentation> </xsd:annotation> <xsd:complexType> <xsd:attribute name="name" default=""/> <xsd:attribute name="group-id" default="DEFAULT_GROUP"/> <xsd:attribute name="data-id" use="required"/> <xsd:attribute name="data-ids"/> <xsd:attribute name="auto-refreshed" default="false"/> <xsd:attribute name="first" default="false"/> <xsd:attribute name="before" default=""/> <xsd:attribute name="after" default=""/> <xsd:attribute name="type" default="properties" /> </xsd:complexType> </xsd:element> </xsd:schema>
2. 实现 NamespaceHandler 和 BeanDefinitionParser
public class NacosNamespaceHandler extends NamespaceHandlerSupport { @Override public void init() { registerBeanDefinitionParser("annotation-driven", new NacosAnnotationDrivenBeanDefinitionParser()); registerBeanDefinitionParser("global-properties", new GlobalNacosPropertiesBeanDefinitionParser()); registerBeanDefinitionParser("property-source", new NacosPropertySourceBeanDefinitionParser()); } }
3. 编写 spring.handlers 和 spring.schemas 文件
http://nacos.io/schema/nacos=com.alibaba.nacos.spring.context.config.xml.NacosNamespaceHandler
http://nacos.io/schema/nacos.xsd=META-INF/schemas/nacos.xsd
以上是关于nacos-spring-project 的 xml 配置的主要内容,如果未能解决你的问题,请参考以下文章